/** * Store relations for cache * * @param $relations * @internal param $result */ protected function fpCacheRelations($relations) { foreach ($relations as $items) { if (empty($items)) { continue; } $count_item = count($items); if ($count_item > FPCache::elementLimit()) { if (!empty($items[0])) { FPCache::element($items[0]->getTable()); } } if ($items instanceof \Illuminate\Database\Eloquent\Collection) { foreach ($items as $item) { if ($count_item <= FPCache::elementLimit()) { FPCache::element($item->getTable(), $item->getKey()); } $recursiveRelations = $item->getRelations(); // recursive call if not empty relations if (!empty($recursiveRelations)) { $this->fpCacheRelations($recursiveRelations); } } } else { FPCache::element($items->getTable(), $items->getKey()); } } }
/** * Delete cached items by events */ public static function boot() { parent::boot(); self::created(function ($model) { FPCache::deleteByModule($model->getTable()); }); self::deleted(function ($model) { FPCache::deleteByModule($model->getTable()); FPCache::deleteByModule($model->getTable(), $model->getKey()); }); self::updated(function ($model) { FPCache::deleteByModule($model->getTable(), $model->getKey()); }); }