/** * Update or create an item in cache from the database item * * @param ItemDetailsUpdated $event * @return \App\Models\Item */ public function handle(ItemDetailsUpdated $event) { $item = $event->item; $cache_item = new CacheItem(); $cache_item->createOrUpdate($item->id, $item->toArray()); return $item; }
/** * Save all tradeable items into one key for fast * and easy access when the user requests "all" * * @param AllPricesUpdated $event */ public function handle(AllPricesUpdated $event) { // Get all tradeable items $ids = (new Item())->where('tradeable', true)->lists('id'); $ids = CacheItem::prefixIdentifier($ids); // Grab the collection of requested items $collection = Redis::mget($ids); foreach ($collection as &$item) { $item = unserialize($item); if (!$item) { continue; } // Only save a few keys, so we don't blow up the redis storage D: $item = array_reverse_dot(array_only(array_dot($item), $this->keys)); } // Save them into the cache under the specified key Redis::set(CacheItem::$cache_prefix . self::$key, serialize($collection)); }
/** * Get the requested items' identifiers * * @param $ids * @return array|null */ private function requestedIdentifiers($ids) { $ids = $this->getInput('ids', $ids); if (!$ids) { return false; } if (!is_array($ids)) { $ids = explode(',', $ids); } $ids = array_values(array_unique($ids)); return CacheItem::prefixIdentifier($ids); }