public function fetch($key) { if (apcu_exists($key)) { return apcu_fetch($key); } return false; }
/** * {@inheritdoc} */ public function has($key) { if (!apcu_exists($key)) { return false; } return true; }
/** * {@inheritdoc} */ public function has($name) { if ($this->driver == self::APCU_DRIVER) { return apcu_exists($this->prefix . $name); } return apc_exists($this->prefix . $name); }
public function fetch($key, $default = '') { if (!apcu_exists($this->hash($key))) { return $default; } return apcu_fetch($this->hash($key)); }
/** * Test purging the apcu cache store. */ public function test_purge() { if (!cachestore_apcu::are_requirements_met()) { $this->markTestSkipped('Could not test cachestore_apcu. Requirements are not met.'); } $definition = cache_definition::load_adhoc(cache_store::MODE_APPLICATION, 'cachestore_apcu', 'phpunit_test'); $instance = cachestore_apcu::initialise_unit_test_instance($definition); // Test a simple purge return. $this->assertTrue($instance->purge()); // Test purge works. $this->assertTrue($instance->set('test', 'monster')); $this->assertSame('monster', $instance->get('test')); $this->assertTrue($instance->purge()); $this->assertFalse($instance->get('test')); // Test purge with custom data. $this->assertTrue($instance->set('test', 'monster')); $this->assertSame('monster', $instance->get('test')); $this->assertTrue(apcu_store('test', 'pirate', 180)); $this->assertSame('monster', $instance->get('test')); $this->assertTrue(apcu_exists('test')); $this->assertSame('pirate', apcu_fetch('test')); // Purge and check that our data is gone but the the custom data is still there. $this->assertTrue($instance->purge()); $this->assertFalse($instance->get('test')); $this->assertTrue(apcu_exists('test')); $this->assertSame('pirate', apcu_fetch('test')); }
public function has($key) { if ($this->apcu) { return apcu_exists((string) $key); } return apc_exists((string) $key); }
public function read() { if (!apcu_exists($this->key)) { return array('_global' => array()); } return apcu_fetch($this->key); }
/** * @param string $key * @return bool */ protected static function cacheHas($key) { if (self::apcuExists()) { return apcu_exists($key); } return false; }
public static function increment($host) { if (!apcu_exists(self::$prefix . $host)) { apcu_store(self::$prefix . $host, 0, self::$ttl); } apcu_inc(self::$prefix . $host); return apcu_fetch(self::$prefix . $host); }
public function exist($name) { if ($this->hasAPCu) { return apcu_exists($name); } else { return isset($_SESSION[$name]); } }
public static function exists($k) { if (function_exists('apc_exists')) { return apc_exists($k); } elseif (function_exists('apcu_exists')) { return apcu_exists($k); } return false; }
public function getHandlers() { $key = $this->_mapTags($this->_handlers_name, 0); if (apcu_exists($key)) { $result = apcu_fetch($key); return $result; } return array(); }
/** * {@inheritdoc } */ public function has($key) { $tKey = $this->getKey($key); if (function_exists("\\apcu_exists") || function_exists("\\apc_exists")) { return (bool) ($this->apcu ? \apcu_exists($tKey) : \apc_exists($tKey)); } else { $result = false; $this->apcu ? \apcu_fetch($tKey, $result) : \apc_fetch($tKey, $result); return (bool) $result; } }
public function decr($key, $value = 1) { /** * @todo When we only support php 7 or higher remove this hack * * https://github.com/krakjoe/apcu/issues/166 */ if (apcu_exists($key . self::KEY_SUFFIX)) { return apcu_dec($key . self::KEY_SUFFIX, $value); } else { return apcu_set($key . self::KEY_SUFFIX, -$value); } }
/** * Test that the Moodle APCu store doesn't cross paths with other code using APCu as well. */ public function test_cross_application_interaction() { $definition = cache_definition::load_adhoc(cache_store::MODE_APPLICATION, 'cachestore_apcu', 'phpunit_test'); $instance = cachestore_apcu::initialise_unit_test_instance($definition); // Test purge with custom data. $this->assertTrue($instance->set('test', 'monster')); $this->assertSame('monster', $instance->get('test')); $this->assertTrue(apcu_store('test', 'pirate', 180)); $this->assertSame('monster', $instance->get('test')); $this->assertTrue(apcu_exists('test')); $this->assertSame('pirate', apcu_fetch('test')); // Purge and check that our data is gone but the the custom data is still there. $this->assertTrue($instance->purge()); $this->assertFalse($instance->get('test')); $this->assertTrue(apcu_exists('test')); $this->assertSame('pirate', apcu_fetch('test')); }
public function testApcu() { $key = __CLASS__; apcu_delete($key); $this->assertFalse(apcu_exists($key)); $this->assertTrue(apcu_add($key, 123)); $this->assertTrue(apcu_exists($key)); $this->assertSame(array($key => -1), apcu_add(array($key => 123))); $this->assertSame(123, apcu_fetch($key)); $this->assertTrue(apcu_store($key, 124)); $this->assertSame(124, apcu_fetch($key)); $this->assertSame(125, apcu_inc($key)); $this->assertSame(124, apcu_dec($key)); $this->assertTrue(apcu_cas($key, 124, 123)); $this->assertFalse(apcu_cas($key, 124, 123)); $this->assertTrue(apcu_delete($key)); $this->assertFalse(apcu_delete($key)); $this->assertArrayHasKey('cache_list', apcu_cache_info()); }
public function read() { try { $key = $this->input->get('key', '', 'raw'); if (empty($key) || !apcu_exists($key)) { throw new \Exception('Invalid Key: ' . $key); } $data = apcu_fetch($key, $success); if (!$success) { \Dsc\System::addMessage('Fetching data unsuccessful', 'error'); } $this->app->set('key', $key); $this->app->set('data', $data); echo \Dsc\System::instance()->get('theme')->renderTheme('Admin/Views::cache/apcu_read.php'); } catch (\Exception $e) { \Dsc\System::addMessage($e->getMessage(), 'error'); $this->app->reroute('/admin/cache/apcu'); } }
public function file($id, $file, $format = '', $readCache = true, $writeCache = true) { if (!is_string($id)) { throw new \InvalidArgumentException('Expected string as first parameter.', E_ERROR); } if (apcu_exists($id)) { if ($readCache === true && $this->settingCache === true) { return apcu_fetch($id); } } switch ($format) { case 'yml': $data = \Symfony\Component\Yaml\Yaml::parse($file); break; default: throw new \Exception(sprintf('Requested format "%s" is not supported, refer to manual for supported formats.', $format), E_ERROR); } if ($writeCache === true && $this->settingCache === true) { apcu_store($id, $data); } return $data; }
/** * Unlock cached item * * @param string $id The cache data ID * @param string $group The cache data group * * @return boolean * * @since 3.5 */ public function unlock($id, $group = null) { $cache_id = $this->_getCacheId($id, $group) . '_lock'; // The apcu_delete function returns false if the ID does not exist if (apcu_exists($cache_id)) { return apcu_delete($cache_id); } return true; }
/** * Check if entry exists in memory * * @param string $key * * @return boolean */ public function exists($key) { return apcu_exists($this->getFinalKey($key)); }
/** * Internal method to replace an existing item. * * @param string $normalizedKey * @param mixed $value * @return bool * @throws Exception\ExceptionInterface */ protected function internalReplaceItem(&$normalizedKey, &$value) { $options = $this->getOptions(); $ttl = $options->getTtl(); $namespace = $options->getNamespace(); $prefix = $namespace === '' ? '' : $namespace . $options->getNamespaceSeparator(); $internalKey = $prefix . $normalizedKey; if (!apcu_exists($internalKey)) { return false; } if (!apcu_store($internalKey, $value, $ttl)) { $type = is_object($value) ? get_class($value) : gettype($value); throw new Exception\RuntimeException("apcu_store('{$internalKey}', <{$type}>, {$ttl}) failed"); } return true; }
/** * {@inheritdoc} */ protected function doHave($id) { return apcu_exists($id); }
function monitorIp() { $link = Link::get_link('domoleaf'); if (apcu_exists('monitorIp')) { return json_decode(apcu_fetch('monitorIp')); } $list = array(); $sql = 'SELECT mac_addr, ip_addr, hostname, last_update FROM ip_monitor ORDER BY hostname'; $req = $link->prepare($sql); $req->execute() or die(error_log(serialize($req->errorInfo()))); while ($do = $req->fetch(PDO::FETCH_OBJ)) { $list[] = clone $do; } apcu_store('monitorIp', json_encode($list), 5); return $list; }
public function exists($id) { return apcu_exists($this->prefix . $id); }
public function exists($key) { return \apcu_exists($this->_prefix . $key); }
/** * {@inheritdoc} */ public function has($key) { return apcu_exists($key); }
/** * Test is a cache has all of the given keys. * * @param array $keys * @return bool True if the cache has all of the given keys, false otherwise. */ public function has_all(array $keys) { foreach ($keys as $arraykey => $key) { $keys[$arraykey] = $this->prepare_key($key); } $result = apcu_exists($keys); return count($result) === count($keys); }
/** * Checks whether a specified key exists in the cache. * This can be faster than getting the value from the cache if the data is big. * Note that this method does not check whether the dependency associated * with the cached data, if there is any, has changed. So a call to [[get]] * may return false while exists returns true. * @param mixed $key a key identifying the cached value. This can be a simple string or * a complex data structure consisting of factors representing the key. * @return boolean true if a value exists in cache, false if the value is not in the cache or expired. */ public function exists($key) { $key = $this->buildKey($key); return $this->useApcu ? apcu_exists($key) : apc_exists($key); }
/** * Confirms if the cache contains specified cache item. * * Note: This method MAY avoid retrieving the cached value for performance reasons. * This could result in a race condition with CacheItemInterface::get(). To avoid * such situation use CacheItemInterface::isHit() instead. * * @param string $key * The key for which to check existence. * * @throws InvalidArgumentException * If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException * MUST be thrown. * * @return bool * True if item exists in the cache, false otherwise. */ public function hasItem($key) { $this->assertValidKey($key); if ($this->legacy) { $exists = apc_exists($key); } else { $exists = apcu_exists($key); } return $this->isItemInDeferred($key) || $exists; }
/** * {@inheritdoc} */ public function get($key) { $k = self::$PREFIX . $key; return apcu_exists($k) ? apcu_fetch($k) : null; }