當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。