Cache::set PHP Method

set() public method

Store value in cache
public set ( $key, $val, $ttl ) : mixed | FALSE
$key string
$val mixed
$ttl int
return mixed | FALSE
    function set($key, $val, $ttl = 0)
    {
        $fw = Base::instance();
        if (!$this->dsn) {
            return TRUE;
        }
        $ndx = $this->prefix . '.' . $key;
        $time = microtime(TRUE);
        if ($cached = $this->exists($key)) {
            list($time, $ttl) = $cached;
        }
        $data = $fw->serialize([$val, $time, $ttl]);
        $parts = explode('=', $this->dsn, 2);
        switch ($parts[0]) {
            case 'apc':
            case 'apcu':
                return apc_store($ndx, $data, $ttl);
            case 'redis':
                return $this->ref->set($ndx, $data, $ttl ? ['ex' => $ttl] : []);
            case 'memcache':
                return memcache_set($this->ref, $ndx, $data, 0, $ttl);
            case 'wincache':
                return wincache_ucache_set($ndx, $data, $ttl);
            case 'xcache':
                return xcache_set($ndx, $data, $ttl);
            case 'folder':
                return $fw->write($parts[1] . $ndx, $data);
        }
        return FALSE;
    }

Usage Example

コード例 #1
0
 /**
  * Invalidate all cached resources where the specified user ids were used as either the
  * owner or viewer id when a signed or OAuth request was made for the content by the application
  * identified in the security token.
  * @param opensocialIds Set of user ids to invalidate authenticated/signed content for
  * @param token identifying the calling application
  */
 function invalidateUserResources(array $opensocialIds, SecurityToken $token)
 {
     foreach ($opensocialIds as $opensocialId) {
         ++self::$marker;
         self::$makerCache->set('marker', self::$marker);
         $this->invalidationEntry->set($this->getKey($opensocialId, $token), self::$marker);
     }
 }
All Usage Examples Of Cache::set