当前位置: 首页>>代码示例>>PHP>>正文


PHP cache_definition类代码示例

本文整理汇总了PHP中cache_definition的典型用法代码示例。如果您正苦于以下问题:PHP cache_definition类的具体用法?PHP cache_definition怎么用?PHP cache_definition使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了cache_definition类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: test_purge

 /**
  * 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'));
 }
开发者ID:linnaea,项目名称:moodle-cachestore_apcu,代码行数:30,代码来源:apcu_test.php

示例2: test_test_instance

 /**
  * Run the unit tests for the store.
  */
 public function test_test_instance()
 {
     $class = $this->get_class_name();
     $modes = $class::get_supported_modes();
     if ($modes & cache_store::MODE_APPLICATION) {
         $definition = cache_definition::load_adhoc(cache_store::MODE_APPLICATION, $class, 'phpunit_test');
         $instance = new $class($class . '_test', $class::unit_test_configuration());
         if (!$instance->is_ready()) {
             $this->markTestSkipped('Could not test ' . $class . '. No test instance configured for application caches.');
         } else {
             $instance->initialise($definition);
             $this->run_tests($instance);
         }
     }
     if ($modes & cache_store::MODE_SESSION) {
         $definition = cache_definition::load_adhoc(cache_store::MODE_SESSION, $class, 'phpunit_test');
         $instance = new $class($class . '_test', $class::unit_test_configuration());
         if (!$instance->is_ready()) {
             $this->markTestSkipped('Could not test ' . $class . '. No test instance configured for session caches.');
         } else {
             $instance->initialise($definition);
             $this->run_tests($instance);
         }
     }
     if ($modes & cache_store::MODE_REQUEST) {
         $definition = cache_definition::load_adhoc(cache_store::MODE_REQUEST, $class, 'phpunit_test');
         $instance = new $class($class . '_test', $class::unit_test_configuration());
         if (!$instance->is_ready()) {
             $this->markTestSkipped('Could not test ' . $class . '. No test instance configured for request caches.');
         } else {
             $instance->initialise($definition);
             $this->run_tests($instance);
         }
     }
 }
开发者ID:lucaboesch,项目名称:moodle,代码行数:38,代码来源:stores.php

示例3: test_test_instance

 /**
  * Run the unit tests for the store.
  */
 public function test_test_instance()
 {
     $class = $this->get_class_name();
     if (!class_exists($class) || !method_exists($class, 'initialise_test_instance') || !$class::are_requirements_met()) {
         $this->markTestSkipped('Could not test ' . $class . '. Requirements are not met.');
     }
     $modes = $class::get_supported_modes();
     if ($modes & cache_store::MODE_APPLICATION) {
         $definition = cache_definition::load_adhoc(cache_store::MODE_APPLICATION, $class, 'phpunit_test');
         $instance = $class::initialise_unit_test_instance($definition);
         if (!$instance) {
             $this->markTestSkipped('Could not test ' . $class . '. No test instance configured for application caches.');
         } else {
             $this->run_tests($instance);
         }
     }
     if ($modes & cache_store::MODE_SESSION) {
         $definition = cache_definition::load_adhoc(cache_store::MODE_SESSION, $class, 'phpunit_test');
         $instance = $class::initialise_unit_test_instance($definition);
         if (!$instance) {
             $this->markTestSkipped('Could not test ' . $class . '. No test instance configured for session caches.');
         } else {
             $this->run_tests($instance);
         }
     }
     if ($modes & cache_store::MODE_REQUEST) {
         $definition = cache_definition::load_adhoc(cache_store::MODE_REQUEST, $class, 'phpunit_test');
         $instance = $class::initialise_unit_test_instance($definition);
         if (!$instance) {
             $this->markTestSkipped('Could not test ' . $class . '. No test instance configured for request caches.');
         } else {
             $this->run_tests($instance);
         }
     }
 }
开发者ID:abhilash1994,项目名称:moodle,代码行数:38,代码来源:stores.php

示例4: test_different_caches_have_different_prefixes

 public function test_different_caches_have_different_prefixes()
 {
     $definition = cache_definition::load_adhoc(cache_store::MODE_APPLICATION, 'cachestore_apcu', 'phpunit_test');
     $instance = cachestore_apcu::initialise_unit_test_instance($definition);
     $definition2 = cache_definition::load_adhoc(cache_store::MODE_APPLICATION, 'cachestore_apcu', 'phpunit_test2');
     $instance2 = cachestore_apcu::initialise_unit_test_instance($definition2);
     $instance->set('test1', 1);
     $this->assertFalse($instance2->get('test1'));
     $instance2->purge();
     $this->assertSame(1, $instance->get('test1'));
 }
开发者ID:janeklb,项目名称:moodle,代码行数:11,代码来源:apcu_test.php

示例5: setUp

 protected function setUp()
 {
     if (!defined('CACHESTORE_REDIS_TEST_SERVER')) {
         $this->markTestSkipped('Must define CACHESTORE_REDIS_TEST_SERVER to test Redis cache store');
     }
     if (!cachestore_redis::are_requirements_met()) {
         $this->markTestSkipped('Requirements for Redis cache store are not met');
     }
     $this->store = new cachestore_redis('test', array('server' => CACHESTORE_REDIS_TEST_SERVER, 'prefix' => 'phpunit'));
     $this->store->initialise(cache_definition::load_adhoc(cache_store::MODE_APPLICATION, 'foo_bar', 'baz'));
 }
开发者ID:troywilliams,项目名称:moodle-cachestore_redis,代码行数:11,代码来源:lib_test.php

示例6: create_cachestore_redis

 /**
  * Creates the required cachestore for the tests to run against Redis.
  *
  * @return cachestore_redis
  */
 protected function create_cachestore_redis()
 {
     /** @var cache_definition $definition */
     $definition = cache_definition::load_adhoc(cache_store::MODE_APPLICATION, 'cachestore_redis', 'phpunit_test');
     $store = new cachestore_redis('Test', cachestore_redis::unit_test_configuration());
     $store->initialise($definition);
     $this->store = $store;
     if (!$store) {
         $this->markTestSkipped();
     }
     return $store;
 }
开发者ID:lucaboesch,项目名称:moodle,代码行数:17,代码来源:redis_test.php

示例7: test_collection_name

 /**
  * A small additional test to make sure definitions that hash a hash starting with a number work OK
  */
 public function test_collection_name()
 {
     // This generates a definition that has a hash starting with a number. MDL-46208.
     $definition = cache_definition::load_adhoc(cache_store::MODE_APPLICATION, 'cachestore_mongodb', 'abc');
     $instance = cachestore_mongodb::initialise_test_instance($definition);
     if (!$instance) {
         $this->markTestSkipped();
     }
     $this->assertTrue($instance->set(1, 'alpha'));
     $this->assertTrue($instance->set(2, 'beta'));
     $this->assertEquals('alpha', $instance->get(1));
     $this->assertEquals('beta', $instance->get(2));
     $this->assertEquals(array(1 => 'alpha', 2 => 'beta'), $instance->get_many(array(1, 2)));
 }
开发者ID:EmmanuelYupit,项目名称:educursos,代码行数:17,代码来源:mongodb_test.php

示例8: test_cache_get_with_prescan_and_purge

 /**
  * Testing cachestore_file::get with prescan enabled and with
  * deleting the cache between the prescan and the call to get.
  *
  * The deleting of cache simulates some other process purging
  * the cache.
  */
 public function test_cache_get_with_prescan_and_purge()
 {
     global $CFG;
     $definition = cache_definition::load_adhoc(cache_store::MODE_REQUEST, 'cachestore_file', 'phpunit_test');
     $name = 'File test';
     $path = make_cache_directory('cachestore_file_test');
     $cache = new cachestore_file($name, array('path' => $path, 'prescan' => true));
     $cache->initialise($definition);
     $cache->set('testing', 'value');
     $path = make_cache_directory('cachestore_file_test');
     $cache = new cachestore_file($name, array('path' => $path, 'prescan' => true));
     $cache->initialise($definition);
     // Let's pretend that some other process purged caches.
     remove_dir($CFG->cachedir . '/cachestore_file_test', true);
     make_cache_directory('cachestore_file_test');
     $cache->get('testing');
 }
开发者ID:evltuma,项目名称:moodle,代码行数:24,代码来源:file_test.php

示例9: test_valid_keys

 /**
  * Tests the valid keys to ensure they work.
  */
 public function test_valid_keys()
 {
     $definition = cache_definition::load_adhoc(cache_store::MODE_APPLICATION, 'cachestore_memcached', 'phpunit_test');
     $instance = cachestore_memcached::initialise_test_instance($definition);
     if (!$instance) {
         // Something prevented memcached store to be inited (extension, TEST_CACHESTORE_MEMCACHED_TESTSERVERS...).
         $this->markTestSkipped();
     }
     $keys = array('abc', 'ABC', '123', 'aB1', '1aB', 'a-1', '1-a', '-a1', 'a1-', 'a_1', '1_a', '_a1', 'a1_');
     foreach ($keys as $key) {
         $this->assertTrue($instance->set($key, $key), "Failed to set key `{$key}`");
     }
     foreach ($keys as $key) {
         $this->assertEquals($key, $instance->get($key), "Failed to get key `{$key}`");
     }
     $values = $instance->get_many($keys);
     foreach ($values as $key => $value) {
         $this->assertEquals($key, $value);
     }
 }
开发者ID:EmmanuelYupit,项目名称:educursos,代码行数:23,代码来源:memcached_test.php

示例10: test_maxsize

 /**
  * Test the maxsize option.
  */
 public function test_maxsize()
 {
     $defid = 'phpunit/testmaxsize';
     $config = cache_config_phpunittest::instance();
     $config->phpunit_add_definition($defid, array('mode' => cache_store::MODE_REQUEST, 'component' => 'phpunit', 'area' => 'testmaxsize', 'maxsize' => 3));
     $definition = cache_definition::load($defid, $config->get_definition_by_id($defid));
     $instance = cachestore_static::initialise_test_instance($definition);
     $this->assertTrue($instance->set('key1', 'value1'));
     $this->assertTrue($instance->set('key2', 'value2'));
     $this->assertTrue($instance->set('key3', 'value3'));
     $this->assertTrue($instance->has('key1'));
     $this->assertTrue($instance->has('key2'));
     $this->assertTrue($instance->has('key3'));
     $this->assertTrue($instance->set('key4', 'value4'));
     $this->assertTrue($instance->set('key5', 'value5'));
     $this->assertFalse($instance->has('key1'));
     $this->assertFalse($instance->has('key2'));
     $this->assertTrue($instance->has('key3'));
     $this->assertTrue($instance->has('key4'));
     $this->assertTrue($instance->has('key5'));
     $this->assertFalse($instance->get('key1'));
     $this->assertFalse($instance->get('key2'));
     $this->assertEquals('value3', $instance->get('key3'));
     $this->assertEquals('value4', $instance->get('key4'));
     $this->assertEquals('value5', $instance->get('key5'));
     // Test adding one more.
     $this->assertTrue($instance->set('key6', 'value6'));
     $this->assertFalse($instance->get('key3'));
     // Test reducing and then adding to make sure we don't lost one.
     $this->assertTrue($instance->delete('key6'));
     $this->assertTrue($instance->set('key7', 'value7'));
     $this->assertEquals('value4', $instance->get('key4'));
     // Set the same key three times to make sure it doesn't count overrides.
     for ($i = 0; $i < 3; $i++) {
         $this->assertTrue($instance->set('key8', 'value8'));
     }
     $this->assertEquals('value7', $instance->get('key7'), 'Overrides are incorrectly incrementing size');
     // Test adding many.
     $this->assertEquals(3, $instance->set_many(array(array('key' => 'keyA', 'value' => 'valueA'), array('key' => 'keyB', 'value' => 'valueB'), array('key' => 'keyC', 'value' => 'valueC'))));
     $this->assertEquals(array('key4' => false, 'key5' => false, 'key6' => false, 'key7' => false, 'keyA' => 'valueA', 'keyB' => 'valueB', 'keyC' => 'valueC'), $instance->get_many(array('key4', 'key5', 'key6', 'key7', 'keyA', 'keyB', 'keyC')));
 }
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:44,代码来源:static_test.php

示例11: static_acceleration_set

 /**
  * Sets a key value pair into the static acceleration array.
  *
  * @param string $key The parsed key
  * @param mixed $data
  * @return bool
  */
 protected function static_acceleration_set($key, $data)
 {
     if ($this->staticaccelerationsize !== false && isset($this->staticaccelerationkeys[$key])) {
         $this->staticaccelerationcount--;
         unset($this->staticaccelerationkeys[$key]);
     }
     // We serialize anything that's not;
     // 1. A known scalar safe value.
     // 2. A definition that says it's simpledata.  We trust it that it doesn't contain dangerous references.
     // 3. An object that handles dereferencing by itself.
     if (is_scalar($data) || $this->definition->uses_simple_data() || $data instanceof cache_cached_object) {
         $this->staticaccelerationarray[$key]['data'] = $data;
         $this->staticaccelerationarray[$key]['serialized'] = false;
     } else {
         $this->staticaccelerationarray[$key]['data'] = serialize($data);
         $this->staticaccelerationarray[$key]['serialized'] = true;
     }
     if ($this->staticaccelerationsize !== false) {
         $this->staticaccelerationcount++;
         $this->staticaccelerationkeys[$key] = $key;
         if ($this->staticaccelerationcount > $this->staticaccelerationsize) {
             $dropkey = array_shift($this->staticaccelerationkeys);
             unset($this->staticaccelerationarray[$dropkey]);
             $this->staticaccelerationcount--;
         }
     }
     return true;
 }
开发者ID:gabrielrosset,项目名称:moodle,代码行数:35,代码来源:loaders.php

示例12: set

 /**
  * Sets an item in the cache given its key and data value.
  *
  * @param string $key The key to use.
  * @param mixed $data The data to set.
  * @return bool True if the operation was a success false otherwise.
  */
 public function set($key, $data)
 {
     if ($this->encode) {
         // We must serialise this data.
         $data = serialize($data);
     }
     return $this->connection->set($this->parse_key($key), $data, MEMCACHE_COMPRESSED, $this->definition->get_ttl());
 }
开发者ID:EmmanuelYupit,项目名称:educursos,代码行数:15,代码来源:lib.php

示例13: set_many

 /**
  * Sets many items in the cache in a single transaction.
  *
  * @param array $keyvaluearray An array of key value pairs. Each item in the array will be an associative array with two
  *      keys, 'key' and 'value'.
  * @return int The number of items successfully set. It is up to the developer to check this matches the number of items
  *      sent ... if they care that is.
  */
 public function set_many(array $keyvaluearray)
 {
     $store = array();
     foreach ($keyvaluearray as $pair) {
         $store[$this->prepare_key($pair['key'])] = $pair['value'];
     }
     $result = apcu_store($store, null, $this->definition->get_ttl());
     return count($keyvaluearray) - count($result);
 }
开发者ID:linnaea,项目名称:moodle-cachestore_apcu,代码行数:17,代码来源:lib.php

示例14: set_many

 /**
  * Sets many items in the cache in a single transaction.
  *
  * @param array $keyvaluearray An array of key value pairs. Each item in the array will be an associative array with two
  *      keys, 'key' and 'value'.
  * @return int The number of items successfully set. It is up to the developer to check this matches the number of items
  *      sent ... if they care that is.
  */
 public function set_many(array $keyvaluearray)
 {
     $count = 0;
     foreach ($keyvaluearray as $pair) {
         if ($this->connection->set($this->parse_key($pair['key']), $pair['value'], MEMCACHE_COMPRESSED, $this->definition->get_ttl())) {
             $count++;
         }
     }
     return $count;
 }
开发者ID:helenagarcia90,项目名称:moodle,代码行数:18,代码来源:lib.php

示例15: set

 /**
  * Sets an item in the cache given its key and data value.
  *
  * @param string $key The key to use.
  * @param mixed $data The data to set.
  * @return bool True if the operation was a success false otherwise.
  */
 public function set($key, $data)
 {
     if ($this->clustered) {
         $status = true;
         foreach ($this->setconnections as $connection) {
             $status = $connection->set($this->parse_key($key), $data, MEMCACHE_COMPRESSED, $this->definition->get_ttl()) && $status;
         }
         return $status;
     }
     return $this->connection->set($this->parse_key($key), $data, MEMCACHE_COMPRESSED, $this->definition->get_ttl());
 }
开发者ID:abhilash1994,项目名称:moodle,代码行数:18,代码来源:lib.php


注:本文中的cache_definition类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。