public function testAccess() { $time = time(); $cache = new CacheObject('type', 'id', ''); sleep(1); $cache->access(); $accessTime = $time + 1; $this->assertEquals(1, $cache->getTimesAccessed()); $this->assertEquals($time, $cache->getCreationDate()); $this->assertEquals($accessTime, $cache->getLastAccessDate()); }
/** * Processes the read of a cache object * @param CacheObject $cacheObject The cache object to process * @return mixed The value of the cache object */ protected function processObject(CacheObject $cacheObject = null) { if (!$cacheObject) { return null; } $cacheObject->access(); if ($this->needCleanUp($cacheObject)) { $this->io->clearCache($cacheObject->getType(), $cacheObject->getId()); } else { $this->io->writeToCache($cacheObject); } return $cacheObject->getData(); }
public function testGetCleansUpWhenCleanUpAgeReached() { $type = 'type'; $id = 'id'; $value = 'value'; $object = new CacheObject($type, $id, $value); sleep(3); $object->access(); $IOMock = $this->getMock('zibo\\library\\cache\\io\\CacheIO', array('readFromCache', 'clearCache', 'writeToCache')); $IOMock->expects($this->once())->method('readFromCache')->with($this->equalTo($type), $this->equalTo($id))->will($this->returnValue($object)); $IOMock->expects($this->once())->method('clearCache')->with($this->equalTo($type), $this->equalTo($id)); $cache = new ExtendedCache($IOMock); $cache->setCleanUpAge(2); $cache->get($type, $id); }