/** * Stores a value into the cache. * * The $value argument can be any item that can be serialized by PHP, * although the method of serialization is left up to the Implementing * Library. * * The $ttl can be defined in a number of ways. As an integer or * DateInverval object the argument defines how long before the cache should * expire. As a DateTime object the argument defines the actual expiration * time of the object. Implementations are allowed to use a lower time than * passed, but should not use a longer one. * * If no $ttl is passed then the item can be stored indefinitely or a * default value can be set by the Implementing Library. * * Returns true if the item was successfully stored. * * @param mixed $value * @param int|DateInterval|DateTime $ttl * * @return bool */ public function set($value, $ttl = null) { $context = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext(); $cleaningFactor = $context->get(tubepress_api_const_options_names_Cache::CACHE_CLEAN_FACTOR); $cleaningFactor = intval($cleaningFactor); /** * Handle cleaning factor. */ if ($cleaningFactor > 0 && rand(1, $cleaningFactor) === 1) { $this->_parentCache->flush(); } if ($ttl === null) { $ttl = intval($context->get(tubepress_api_const_options_names_Cache::CACHE_LIFETIME_SECONDS)); } return $this->_delegate->set($value, $ttl); }
private function assertDisabledStash(ehough_stash_interfaces_ItemInterface $item) { $this->assertFalse($item->set('true'), 'storeData returns false for disabled cache'); $this->assertNull($item->get(), 'getData returns null for disabled cache'); $this->assertFalse($item->clear(), 'clear returns false for disabled cache'); $this->assertTrue($item->isMiss(), 'isMiss returns true for disabled cache'); $this->assertFalse($item->extend(), 'extend returns false for disabled cache'); $this->assertTrue($item->lock(100), 'lock returns true for disabled cache'); }