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


PHP cache_helper::invalidate_by_event方法代码示例

本文整理汇总了PHP中cache_helper::invalidate_by_event方法的典型用法代码示例。如果您正苦于以下问题:PHP cache_helper::invalidate_by_event方法的具体用法?PHP cache_helper::invalidate_by_event怎么用?PHP cache_helper::invalidate_by_event使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cache_helper的用法示例。


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

示例1: test_distributed_application_event_invalidation

 /**
  * Tests application cache event invalidation over a distributed setup.
  */
 public function test_distributed_application_event_invalidation()
 {
     global $CFG;
     // This is going to be an intense wee test.
     // We need to add data the to cache, invalidate it by event, manually force it back without MUC knowing to simulate a
     // disconnected/distributed setup (think load balanced server using local cache), instantiate the cache again and finally
     // check that it is not picked up.
     $instance = cache_config_phpunittest::instance();
     $instance->phpunit_add_definition('phpunit/eventinvalidationtest', array('mode' => cache_store::MODE_APPLICATION, 'component' => 'phpunit', 'area' => 'eventinvalidationtest', 'simplekeys' => true, 'simpledata' => true, 'invalidationevents' => array('crazyevent')));
     $cache = cache::make('phpunit', 'eventinvalidationtest');
     $this->assertTrue($cache->set('testkey1', 'test data 1'));
     $this->assertEquals('test data 1', $cache->get('testkey1'));
     cache_helper::invalidate_by_event('crazyevent', array('testkey1'));
     $this->assertFalse($cache->get('testkey1'));
     // OK data added, data invalidated, and invalidation time has been set.
     // Now we need to manually add back the data and adjust the invalidation time.
     $hash = md5(cache_store::MODE_APPLICATION . '/phpunit/eventinvalidationtest/' . $CFG->wwwroot . 'phpunit');
     $timefile = $CFG->dataroot . "/cache/cachestore_file/default_application/phpunit_eventinvalidationtest/las/lastinvalidation-{$hash}.cache";
     // Make sure the file is correct.
     $this->assertTrue(file_exists($timefile));
     $timecont = serialize(cache::now() - 60);
     // Back 60sec in the past to force it to re-invalidate.
     make_writable_directory(dirname($timefile));
     file_put_contents($timefile, $timecont);
     $this->assertTrue(file_exists($timefile));
     $datafile = $CFG->dataroot . "/cache/cachestore_file/default_application/phpunit_eventinvalidationtest/tes/testkey1-{$hash}.cache";
     $datacont = serialize("test data 1");
     make_writable_directory(dirname($datafile));
     file_put_contents($datafile, $datacont);
     $this->assertTrue(file_exists($datafile));
     // Test 1: Rebuild without the event and test its there.
     cache_factory::reset();
     $instance = cache_config_phpunittest::instance();
     $instance->phpunit_add_definition('phpunit/eventinvalidationtest', array('mode' => cache_store::MODE_APPLICATION, 'component' => 'phpunit', 'area' => 'eventinvalidationtest', 'simplekeys' => true, 'simpledata' => true));
     $cache = cache::make('phpunit', 'eventinvalidationtest');
     $this->assertEquals('test data 1', $cache->get('testkey1'));
     // Test 2: Rebuild and test the invalidation of the event via the invalidation cache.
     cache_factory::reset();
     $instance = cache_config_phpunittest::instance();
     $instance->phpunit_add_definition('phpunit/eventinvalidationtest', array('mode' => cache_store::MODE_APPLICATION, 'component' => 'phpunit', 'area' => 'eventinvalidationtest', 'simplekeys' => true, 'simpledata' => true, 'invalidationevents' => array('crazyevent')));
     $cache = cache::make('phpunit', 'eventinvalidationtest');
     $this->assertFalse($cache->get('testkey1'));
 }
开发者ID:Burick,项目名称:moodle,代码行数:46,代码来源:cache_test.php

示例2: test_distributed_application_event_invalidation

 /**
  * Tests application cache event invalidation over a distributed setup.
  */
 public function test_distributed_application_event_invalidation()
 {
     global $CFG;
     // This is going to be an intense wee test.
     // We need to add data the to cache, invalidate it by event, manually force it back without MUC knowing to simulate a
     // disconnected/distributed setup (think load balanced server using local cache), instantiate the cache again and finally
     // check that it is not picked up.
     $instance = cache_config_testing::instance();
     $instance->phpunit_add_definition('phpunit/eventinvalidationtest', array('mode' => cache_store::MODE_APPLICATION, 'component' => 'phpunit', 'area' => 'eventinvalidationtest', 'simplekeys' => true, 'simpledata' => true, 'invalidationevents' => array('crazyevent')));
     $cache = cache::make('phpunit', 'eventinvalidationtest');
     $this->assertTrue($cache->set('testkey1', 'test data 1'));
     $this->assertEquals('test data 1', $cache->get('testkey1'));
     cache_helper::invalidate_by_event('crazyevent', array('testkey1'));
     $this->assertFalse($cache->get('testkey1'));
     // OK data added, data invalidated, and invalidation time has been set.
     // Now we need to manually add back the data and adjust the invalidation time.
     $hash = md5(cache_store::MODE_APPLICATION . '/phpunit/eventinvalidationtest/' . $CFG->wwwroot . 'phpunit');
     $timefile = $CFG->dataroot . "/cache/cachestore_file/default_application/phpunit_eventinvalidationtest/las-cache/lastinvalidation-{$hash}.cache";
     // Make sure the file is correct.
     $this->assertTrue(file_exists($timefile));
     $timecont = serialize(cache::now() - 60);
     // Back 60sec in the past to force it to re-invalidate.
     make_writable_directory(dirname($timefile));
     file_put_contents($timefile, $timecont);
     $this->assertTrue(file_exists($timefile));
     $datafile = $CFG->dataroot . "/cache/cachestore_file/default_application/phpunit_eventinvalidationtest/tes-cache/testkey1-{$hash}.cache";
     $datacont = serialize("test data 1");
     make_writable_directory(dirname($datafile));
     file_put_contents($datafile, $datacont);
     $this->assertTrue(file_exists($datafile));
     // Test 1: Rebuild without the event and test its there.
     cache_factory::reset();
     $instance = cache_config_testing::instance();
     $instance->phpunit_add_definition('phpunit/eventinvalidationtest', array('mode' => cache_store::MODE_APPLICATION, 'component' => 'phpunit', 'area' => 'eventinvalidationtest', 'simplekeys' => true, 'simpledata' => true));
     $cache = cache::make('phpunit', 'eventinvalidationtest');
     $this->assertEquals('test data 1', $cache->get('testkey1'));
     // Test 2: Rebuild and test the invalidation of the event via the invalidation cache.
     cache_factory::reset();
     $instance = cache_config_testing::instance();
     $instance->phpunit_add_definition('phpunit/eventinvalidationtest', array('mode' => cache_store::MODE_APPLICATION, 'component' => 'phpunit', 'area' => 'eventinvalidationtest', 'simplekeys' => true, 'simpledata' => true, 'invalidationevents' => array('crazyevent')));
     $cache = cache::make('phpunit', 'eventinvalidationtest');
     $this->assertFalse($cache->get('testkey1'));
     // Test 3: Verify that an existing lastinvalidation cache file is updated when needed.
     // Make a new cache class.  This should should invalidate testkey2.
     $cache = cache::make('phpunit', 'eventinvalidationtest');
     // Timestamp should have updated to cache::now().
     $this->assertEquals(cache::now(), $cache->get('lastinvalidation'));
     // Set testkey2 data.
     $cache->set('testkey2', 'test data 2');
     // Backdate the event invalidation time by 30 seconds.
     $invalidationcache = cache::make('core', 'eventinvalidation');
     $invalidationcache->set('crazyevent', array('testkey2' => cache::now() - 30));
     // Lastinvalidation should already be cache::now().
     $this->assertEquals(cache::now(), $cache->get('lastinvalidation'));
     // Set it to 15 seconds ago so that we know if it changes.
     $cache->set('lastinvalidation', cache::now() - 15);
     // Make a new cache class.  This should not invalidate anything.
     cache_factory::instance()->reset_cache_instances();
     $cache = cache::make('phpunit', 'eventinvalidationtest');
     // Lastinvalidation shouldn't change since it was already newer than invalidation event.
     $this->assertEquals(cache::now() - 15, $cache->get('lastinvalidation'));
     // Now set the event invalidation to newer than the lastinvalidation time.
     $invalidationcache->set('crazyevent', array('testkey2' => cache::now() - 5));
     // Make a new cache class.  This should should invalidate testkey2.
     cache_factory::instance()->reset_cache_instances();
     $cache = cache::make('phpunit', 'eventinvalidationtest');
     // Lastinvalidation timestamp should have updated to cache::now().
     $this->assertEquals(cache::now(), $cache->get('lastinvalidation'));
     // Now simulate a purge_by_event 5 seconds ago.
     $invalidationcache = cache::make('core', 'eventinvalidation');
     $invalidationcache->set('crazyevent', array('purged' => cache::now() - 5));
     // Set our lastinvalidation timestamp to 15 seconds ago.
     $cache->set('lastinvalidation', cache::now() - 15);
     // Make a new cache class.  This should invalidate the cache.
     cache_factory::instance()->reset_cache_instances();
     $cache = cache::make('phpunit', 'eventinvalidationtest');
     // Lastinvalidation timestamp should have updated to cache::now().
     $this->assertEquals(cache::now(), $cache->get('lastinvalidation'));
 }
开发者ID:alanaipe2015,项目名称:moodle,代码行数:82,代码来源:cache_test.php


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