Example #1
0
 /**
  * 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));
 }
Example #2
0
 /**
  * Request items
  *
  * @param null $ids
  * @return array|bool
  */
 private function itemRequest($ids = null)
 {
     // Request data
     $ids = $this->requestedIdentifiers($ids);
     $language = $this->requestedLanguage();
     $attributes = $this->requestedAttributes();
     if (!$ids) {
         return false;
     }
     // Grab the collection of requested items
     $collection = Redis::mget($ids);
     foreach ($collection as &$item) {
         $item = unserialize($item);
         if (!$item) {
             continue;
         }
         // Rename "name" attribute
         $item['name'] = $item['name_' . $language];
         unset($item['name_en']);
         unset($item['name_de']);
         unset($item['name_fr']);
         unset($item['name_es']);
         // Rename "description" attribute
         $item['description'] = $item['description_' . $language];
         unset($item['description_en']);
         unset($item['description_de']);
         unset($item['description_fr']);
         unset($item['description_es']);
         // Only return requested attributes
         $item = array_reverse_dot(array_only(array_dot($item), $attributes));
     }
     return $collection;
 }