for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* AnimeDb package
*
* @package AnimeDb
* @author Peter Gribanov <[email protected]>
* @copyright Copyright (c) 2014, Peter Gribanov
* @license http://opensource.org/licenses/MIT
*/
namespace AnimeDb\Bundle\CacheTimeKeeperBundle\Service\Driver;
use AnimeDb\Shmop\FixedBlock as BlockShmop;
* Shmop driver
* @package AnimeDb\Bundle\CacheTimeKeeperBundle\Service\Driver
class Shmop extends Base
{
* Cache key salt
* @var string
protected $salt;
* @param string $salt
public function __construct($salt)
$this->salt = $salt;
}
* Get time for key
* @param string $key
* @return \DateTime|null
public function get($key)
$sh = new BlockShmop($this->getIdByKey($key), 10);
if ($time = $sh->read()) {
return new \DateTime(date('Y-m-d H:i:s', $time));
return null;
* Set time for key
* @param \DateTime $time
* @return boolean
public function set($key, \DateTime $time)
if (!($old_time = $sh->read()) || $old_time < $time->getTimestamp()) {
$sh->write($time->getTimestamp());
return true;
* Remove time for key
public function remove($key)
return $sh->delete();
* Get id
* @return integer
public function getIdByKey($key)
return (int)sprintf('%u', crc32($key.$this->salt));