Horde_Cache::set PHP Method

set() public method

Store an object in the cache.
public set ( string $key, string $data, integer $lifetime = null )
$key string Object ID used as the caching key.
$data string Data to store in the cache.
$lifetime integer Object lifetime - i.e. the time before the data becomes available for garbage collection, in seconds. If null use the default Horde GC time. If 0 will not be GC'd.
    public function set($key, $data, $lifetime = null)
    {
        if (!empty($this->_params['compress'])) {
            $compress = new Horde_Compress_Fast();
            $data = $compress->compress($data);
        }
        $lifetime = is_null($lifetime) ? $this->_params['lifetime'] : $lifetime;
        $this->_storage->set($key, $data, $lifetime);
    }

Usage Example

Beispiel #1
0
 /**
  * TODO
  */
 protected function _getAddressBook(array $fields = array())
 {
     $key = 'turba_fb_getAddressBook|' . $GLOBALS['registry']->getAuth() . '|' . md5(implode('.', $fields));
     if ($values = $this->_cache->get($key, 3600)) {
         return json_decode($values, true);
     }
     $cleanfields = implode(', ', $this->_prepareFields($fields));
     try {
         $fql = 'SELECT ' . $cleanfields . ' FROM user WHERE uid IN (' . 'SELECT uid2 FROM friend WHERE uid1=' . $this->_facebook->auth->getLoggedInUser() . ')';
         $results = $this->_facebook->fql->run($fql);
     } catch (Horde_Service_Facebook_Exception $e) {
         Horde::log($e, 'ERR');
         if ($e->getCode() == Horde_Service_Facebook_ErrorCodes::API_EC_PARAM_SESSION_KEY) {
             throw new Turba_Exception(_("You are not connected to Facebook. Create a Facebook connection in the Global Preferences."));
         }
         throw new Turba_Exception($e);
     }
     // Now pull out the results that are arrays
     $addressbook = array();
     foreach ($results as &$result) {
         $addressbook[$result['uid']] = $this->_fqlToTurba($fields, $result);
     }
     $this->_cache->set($key, json_encode($addressbook));
     return $addressbook;
 }
All Usage Examples Of Horde_Cache::set