コード例 #1
0
ファイル: ZendServerShm.php プロジェクト: Baft/Zend-Form
 /**
  * Store data into Zend Data SHM Cache
  *
  * @param  string $internalKey
  * @param  mixed  $value
  * @param  int    $ttl
  * @return void
  * @throws Exception\RuntimeException
  */
 protected function zdcStore($internalKey, $value, $ttl)
 {
     if (!zend_shm_cache_store($internalKey, $value, $ttl)) {
         $valueType = gettype($value);
         throw new Exception\RuntimeException("zend_disk_cache_store({$internalKey}, <{$valueType}>, {$ttl}) failed");
     }
 }
コード例 #2
0
ファイル: ShMem.php プロジェクト: Gradven/what3.1.7
 /**
  * Store data
  *
  * @param mixed  $data        Object to store
  * @param string $id          Cache id
  * @param int    $timeToLive  Time to live in seconds
  *
  */
 protected function _store($data, $id, $timeToLive)
 {
     if (zend_shm_cache_store($this->_options['namespace'] . '::' . $id, $data, $timeToLive) === false) {
         $this->_log('Store operation failed.');
         return false;
     }
     return true;
 }
コード例 #3
0
ファイル: Driver.php プロジェクト: jigoshop/Jigoshop2
 /**
  * @param \Psr\Cache\CacheItemInterface $item
  * @return mixed
  * @throws \InvalidArgumentException
  */
 protected function driverWrite(CacheItemInterface $item)
 {
     /**
      * Check for Cross-Driver type confusion
      */
     if ($item instanceof Item) {
         $ttl = $item->getExpirationDate()->getTimestamp() - time();
         return zend_shm_cache_store($item->getKey(), $this->driverPreWrap($item), $ttl > 0 ? $ttl : 0);
     } else {
         throw new \InvalidArgumentException('Cross-Driver type confusion detected');
     }
 }
コード例 #4
0
ファイル: common.php プロジェクト: bobwuyan/testproject
 /**
  * 获取远程URL,并带缓存$url是URL,time是缓时间,秒为单位,默认300
  */
 public static function geturl($url, $time = 300)
 {
     $md5 = md5($url);
     $cached = zend_shm_cache_fetch($md5);
     //从内存缓存读取
     if ($cached === false || !empty($_GET['update'])) {
         $cached = file_get_contents($url);
         zend_shm_cache_store($md5, $cached, $time);
         //存至内存,最后一个是过期时间,单位为秒
         return $cached;
     } else {
         return $cached;
     }
 }
コード例 #5
0
 function set($key, $value)
 {
     parent::set($key, $value);
     // caching is turned off
     if (!$GLOBALS['external_cache_enabled']) {
         return;
     }
     $external_key = $this->_realKey($key);
     if (EXTERNAL_CACHE_DEBUG) {
         SugarCache::log("Step 3: Converting key ({$key}) to external key ({$external_key})");
     }
     zend_shm_cache_store($external_key, serialize($value), $this->timeout);
     if (EXTERNAL_CACHE_DEBUG) {
         SugarCache::log("Step 4: Added key to Zend cache {$external_key} with value ({$value}) to be stored for " . EXTERNAL_CACHE_INTERVAL_SECONDS . " seconds");
     }
 }
コード例 #6
0
ファイル: SugarCacheZend.php プロジェクト: omusico/sugar_work
 /**
  * @see SugarCacheAbstract::_setExternal()
  */
 protected function _setExternal($key, $value)
 {
     zend_shm_cache_store($key, serialize($value), $this->_expireTimeout);
 }
コード例 #7
0
ファイル: Zendshm.php プロジェクト: crlang44/frapi
 /**
  * Add to the cache
  *
  * Add a new variable to the cache that you will then be able
  * to retrieve using the $this->get($name) method.
  *
  * @param  string  $name   The name of the cache variable to store.
  * @param  string  $value  The value of the cache variable to store.
  * @param  integer $expire When should it expire? Default: 900 seconds.
  * 
  * @return boolean       Depending on the success of the operation, 
  *                       either true or false. 
  */
 public function add($name, $value, $expiry = 900)
 {
     return zend_shm_cache_store($name, $value, $expiry);
 }
コード例 #8
0
ファイル: Shm.php プロジェクト: chrismcmacken/phptools
 public function set($key, $value, $ttl = 0)
 {
     $safeKey = $this->makeKey($key);
     $ret = @zend_shm_cache_store($safeKey, $value, $ttl);
     return $ret;
 }
コード例 #9
0
 /**
  * Veri ataması yapar
  *
  * @param string $name
  * @param mixed $value
  * @param int $time
  * @return mixed
  */
 public function set($name, $value, $time = 3600)
 {
     return zend_shm_cache_store($name, $value, $time);
 }
コード例 #10
0
ファイル: Cache.subs.php プロジェクト: KeiroD/Elkarte
/**
 * Puts value in the cache under key for ttl seconds.
 *
 * - It may "miss" so shouldn't be depended on
 * - Uses the cache engine chosen in the ACP and saved in settings.php
 * - It supports:
 *     Turck MMCache: http://turck-mmcache.sourceforge.net/index_old.html#api
 *     Xcache: http://xcache.lighttpd.net/wiki/XcacheApi
 *     memcache: http://www.php.net/memcache
 *     APC: http://www.php.net/apc
 *     eAccelerator: http://bart.eaccelerator.net/doc/phpdoc/
 *     Zend: http://files.zend.com/help/Zend-Platform/output_cache_functions.htm
 *     Zend: http://files.zend.com/help/Zend-Platform/zend_cache_functions.htm
 *
 * @param string $key
 * @param string|int|mixed[]|null $value
 * @param int $ttl = 120
 */
function cache_put_data($key, $value, $ttl = 120)
{
    global $cache_memcached, $memcached, $cache_hits, $cache_count, $db_show_debug;
    global $cache_accelerator, $cache_enable;
    if (empty($cache_enable)) {
        return;
    }
    $cache_count = isset($cache_count) ? $cache_count + 1 : 1;
    if (isset($db_show_debug) && $db_show_debug === true) {
        $cache_hits[$cache_count] = array('k' => $key, 'd' => 'put', 's' => $value === null ? 0 : strlen(serialize($value)));
        $st = microtime(true);
    }
    $key = cache_get_key($key);
    $value = $value === null ? null : serialize($value);
    switch ($cache_accelerator) {
        case 'memcached':
            // The simple yet efficient memcached.
            if (function_exists('memcached_set') || function_exists('memcache_set') && !empty($cache_memcached)) {
                // Not connected yet?
                if (empty($memcached)) {
                    get_memcached_server();
                }
                if (!$memcached) {
                    return;
                }
                memcache_set($memcached, $key, $value, 0, $ttl);
            }
            break;
        case 'eaccelerator':
            // eAccelerator...
            if (function_exists('eaccelerator_put')) {
                if (mt_rand(0, 10) == 1) {
                    eaccelerator_gc();
                }
                if ($value === null) {
                    @eaccelerator_rm($key);
                } else {
                    eaccelerator_put($key, $value, $ttl);
                }
            }
            break;
        case 'mmcache':
            // Turck MMCache?
            if (function_exists('mmcache_put')) {
                if (mt_rand(0, 10) == 1) {
                    mmcache_gc();
                }
                if ($value === null) {
                    @mmcache_rm($key);
                } else {
                    mmcache_lock($key);
                    mmcache_put($key, $value, $ttl);
                    mmcache_unlock($key);
                }
            }
            break;
        case 'apc':
        case 'apcu':
            // Alternative PHP Cache, ahoy!
            if (function_exists('apc_store')) {
                // An extended key is needed to counteract a bug in APC.
                if ($value === null) {
                    apc_delete($key . 'elkarte');
                } else {
                    apc_store($key . 'elkarte', $value, $ttl);
                }
            }
            break;
        case 'zend':
            // Zend Platform/ZPS/etc.
            if (function_exists('zend_shm_cache_store')) {
                zend_shm_cache_store('ELK::' . $key, $value, $ttl);
            } elseif (function_exists('output_cache_put')) {
                output_cache_put($key, $value);
            }
            break;
        case 'xcache':
            if (function_exists('xcache_set') && ini_get('xcache.var_size') > 0) {
                if ($value === null) {
                    xcache_unset($key);
                } else {
                    xcache_set($key, $value, $ttl);
                }
            }
            break;
        default:
            // Otherwise custom cache?
            if ($value === null) {
                @unlink(CACHEDIR . '/data_' . $key . '.php');
            } else {
                $cache_data = '<' . '?' . 'php if (!defined(\'ELK\')) die; if (' . (time() + $ttl) . ' < time()) $expired = true; else{$expired = false; $value = \'' . addcslashes($value, '\\\'') . '\';}';
                // Write out the cache file, check that the cache write was successful; all the data must be written
                // If it fails due to low diskspace, or other, remove the cache file
                if (@file_put_contents(CACHEDIR . '/data_' . $key . '.php', $cache_data, LOCK_EX) !== strlen($cache_data)) {
                    @unlink(CACHEDIR . '/data_' . $key . '.php');
                }
            }
            break;
    }
    if (function_exists('call_integration_hook')) {
        call_integration_hook('cache_put_data', array($key, $value, $ttl));
    }
    if (isset($db_show_debug) && $db_show_debug === true) {
        $cache_hits[$cache_count]['t'] = microtime(true) - $st;
    }
}
コード例 #11
0
 /**
  * {@inheritdoc}
  */
 protected function doSave($id, $data, $lifeTime = 0)
 {
     return zend_shm_cache_store($id, $data, $lifeTime);
 }
コード例 #12
0
 function pmxCachePut($key, $value, $ttl, $useMember = false, $cleaner = null)
 {
     global $PortaMx_cache, $user_info;
     $st = microtime(true);
     if ($value === null && $cleaner !== null && $useMember) {
         $ckey = $PortaMx_cache['key'] . '-' . $cleaner . '-' . $key;
     } else {
         $ckey = $PortaMx_cache['key'] . ($useMember ? '-' . implode('_', $user_info['groups']) : '') . '-' . $key;
     }
     if (function_exists('zend_shm_cache_store')) {
         zend_shm_cache_store('PMX::' . $ckey, $value, $ttl);
     } elseif (function_exists('output_cache_put')) {
         output_cache_put($ckey, $value);
     }
     if ($value !== null) {
         $PortaMx_cache['vals']['saved'] += strlen($value);
     }
     $PortaMx_cache['vals']['time'] += microtime(true) - $st;
     // handle member groups key?
     if ($useMember && $cleaner === null) {
         pmxCacheMemGroupAcs();
     }
 }
コード例 #13
0
 /**
  * Stores a value identified by a key in cache.
  * This is the implementation of the method declared in the parent class.
  *
  * @param string $key the key identifying the value to be cached
  * @param string $value the value to be cached
  * @param integer $duration the number of seconds in which the cached value will expire. 0 means never expire.
  * @return boolean true if the value is successfully stored into cache, false otherwise
  */
 protected function setValue($key, $value, $duration)
 {
     return zend_shm_cache_store($key, $value, $duration);
 }
コード例 #14
0
 public function store($key, array $document)
 {
     zend_shm_cache_store("MongoObject::{$key}", $document);
 }
コード例 #15
0
ファイル: AspisMain.php プロジェクト: NetPainter/aspis
function load_taint_categories()
{
    global $taint_categories;
    $read_file = true;
    if (isset($_SERVER[0]['HTTP_USER_AGENT'])) {
        $taint_categories = zend_shm_cache_fetch('taint_categories');
        if ($taint_categories !== false) {
            $read_file = false;
        }
    }
    if ($read_file) {
        global $ASPIS_CATEGORIES_FILE;
        $file = file($ASPIS_CATEGORIES_FILE, FILE_USE_INCLUDE_PATH | FILE_IGNORE_NEW_LINES);
        for ($i = 0; $i < count($file); $i++) {
            $line = $file[$i];
            if ($line == "begin") {
                $tc = array(array(), array());
                $reading_sanitisation = 0;
                $reading_sinks = 0;
                $reading_sources = 0;
                while (1) {
                    $line = $file[++$i];
                    if ($line == "end") {
                        break;
                    } else {
                        if ($line == ">sanitisation") {
                            $reading_sanitisation = 1;
                            continue;
                        } else {
                            if ($line == ">sinks") {
                                $reading_sanitisation = 0;
                                $reading_sinks = 1;
                                continue;
                            } else {
                                if ($line == ">sources") {
                                    $reading_sanitisation = 0;
                                    $reading_sinks = 0;
                                    $reading_sources = 1;
                                    continue;
                                }
                            }
                        }
                    }
                    if ($reading_sanitisation) {
                        $tc[0][$line] = 1;
                    } else {
                        if ($reading_sinks || $reading_sources) {
                            $tok1 = strtok($line, "->");
                            $tok2 = strtok("->");
                            if ($tok1 != "" && $tok2 != "") {
                                if ($reading_sinks) {
                                    $tc[1][$tok1] = $tok2;
                                } else {
                                    if ($reading_sources) {
                                        $tc[2][$tok1] = $tok2;
                                    }
                                }
                            } else {
                                die("Invalid guard in the category file");
                            }
                        }
                    }
                }
                $taint_categories[] = $tc;
            }
        }
        if (isset($_SERVER[0]['HTTP_USER_AGENT'])) {
            zend_shm_cache_store('taint_categories', $taint_categories, 24 * 3600);
        }
    }
}
コード例 #16
0
 /**
  * Write datas on $uid key
  * @param mixed $uid
  * @param mixed $mixed
  */
 public function write($uid, $mixed)
 {
     return zend_shm_cache_store($uid, $mixed);
 }
コード例 #17
0
ファイル: AspisLibrary.php プロジェクト: NetPainter/aspis
function Aspis_create_function($params, $code)
{
    global $ASPIS_PIPE_SEND;
    global $ASPIS_PIPE_RECEIVE;
    global $ASPIS_CATEGORIES_FILE;
    //is it there in the cache?
    if (isset($_SERVER[0]['HTTP_USER_AGENT'])) {
        $dynamic_functions = zend_shm_cache_fetch('wp_dynamic_functions');
        if ($dynamic_functions !== false) {
            if (isset($dynamic_functions[$code[0]]) && !empty($dynamic_functions[$code[0]])) {
                //                echo "Dynamic function <br>$code[0]<br> is in cache!<br>";
                return create_function($params[0], $dynamic_functions[$code[0]]);
            }
        }
    }
    $r = posix_mkfifo($ASPIS_PIPE_SEND, 0777);
    if (!$r) {
        unlink($ASPIS_PIPE_SEND);
        $r = posix_mkfifo($ASPIS_PIPE_SEND, 0777);
        if (!$r) {
            die("Could not create pipe {$ASPIS_PIPE_SEND}\n");
        }
    }
    $r = posix_mkfifo($ASPIS_PIPE_RECEIVE, 0777);
    if (!$r) {
        unlink($ASPIS_PIPE_RECEIVE);
        $r = posix_mkfifo($ASPIS_PIPE_RECEIVE, 0777);
        if (!$r) {
            die("Could not create pipe {$ASPIS_PIPE_RECEIVE}\n");
        }
    }
    if (!$r) {
        die("Could not create pipe {$ASPIS_PIPE}\n");
    }
    exec("aspis -in {$ASPIS_PIPE_SEND} -out {$ASPIS_PIPE_RECEIVE} -categories {$ASPIS_CATEGORIES_FILE} -mode online >/dev/null &", $a);
    $handle_send = fopen($ASPIS_PIPE_SEND, 'w');
    fwrite($handle_send, "<?php " . $code[0]);
    fclose($handle_send);
    $a = file($ASPIS_PIPE_RECEIVE);
    array_shift($a);
    unlink($ASPIS_PIPE_SEND);
    unlink($ASPIS_PIPE_RECEIVE);
    $rewritten = implode($a);
    //store it to the cache
    if (isset($_SERVER[0]['HTTP_USER_AGENT'])) {
        $dynamic_functions = zend_shm_cache_fetch('wp_dynamic_functions');
        //        echo "Storing rewritten version: $rewritten<br>";
        if ($dynamic_functions !== false) {
            $dynamic_functions[$code[0]] = $rewritten;
            zend_shm_cache_store('wp_dynamic_functions', $dynamic_functions, 24 * 3600);
        } else {
            $dynamic_functions = array($code[0] => $rewritten);
            zend_shm_cache_store('wp_dynamic_functions', $dynamic_functions, 24 * 3600);
        }
    }
    return array(create_function($params[0], $rewritten), false);
}
コード例 #18
0
ファイル: ZendSHM.php プロジェクト: liulingfu/madserve
 protected function _set($key, $data, $ttl)
 {
     if (zend_shm_cache_store($this->key($key), $data, $ttl) === false) {
         throw new \fluxbb\cache\Exception('Unable to write Zend SHM cache: ' . $key);
     }
 }
コード例 #19
0
ファイル: CZendDataCache.php プロジェクト: IuriiP/yii-tracker
 /**
  * Stores a value identified by a key in cache.
  * This is the implementation of the method declared in the parent class.
  *
  * @param string $key the key identifying the value to be cached
  * @param string $value the value to be cached
  * @param integer $expire the number of seconds in which the cached value will expire. 0 means never expire.
  * @return boolean true if the value is successfully stored into cache, false otherwise
  */
 protected function setValue($key, $value, $expire)
 {
     return zend_shm_cache_store($key, $value, $expire);
 }
コード例 #20
0
 /**
  * {@inheritdoc}
  */
 public function put($key, $data, $ttl = 0)
 {
     return zend_shm_cache_store($key, $data, $ttl);
 }
コード例 #21
0
ファイル: ZendShMem.php プロジェクト: nstapelbroek/Glitch_Lib
 /**
  * Save some string datas into a cache record
  *
  * Note : $data is always "string" (serialization is done by the
  * core not by the backend)
  *
  * @param string $data datas to cache
  * @param string $id cache id
  * @param array $tags array of strings, the cache record will be tagged by each string entry
  * @param int $specificLifetime if != false, set a specific lifetime for this cache record (null => infinite lifetime)
  * @return boolean true if no problem
  */
 public function save($data, $id, $tags = array(), $specificLifetime = false)
 {
     $lifetime = $this->getLifetime($specificLifetime);
     if (zend_shm_cache_store($this->_options['namespace'] . '::' . $id, $data, $lifetime) === false) {
         return false;
     }
     return true;
 }