_readCache($key); if (isset($content) && $content != '') { return $content; } return null; } if (func_num_args() == 2) { return $this->_writeCache($key, $arglist[1]); } // Cutting a piece of the args. $content = array_slice($arglist, 1); return $this->_writeCache($key, $content); } /** * Serializes data in a proper fashion. */ private function _writeCache($key, $object) { $data = str_replace( "'", "\\'", base64_encode(gzcompress(serialize($object))) ); if (User::me()->id) { $cache = Cache::firstOrNew(['user_id' => User::me()->id, 'name' => $key]); $cache->data = $data; $cache->save(); } } /** * Unserializes data. */ private function _readCache($key) { $cache = $this->where('user_id', User::me()->id) ->where('name', $key) ->first(); if (isset($cache)) { return unserialize( gzuncompress(base64_decode(str_replace("\\'", "'", $cache->data))) ); } return false; } }