Skip to content

Instantly share code, notes, and snippets.

@alganet
Forked from henriquemoody/FluentCache.php
Last active December 13, 2015 21:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save alganet/4978752 to your computer and use it in GitHub Desktop.
Save alganet/4978752 to your computer and use it in GitHub Desktop.
<?php
class FluentCache extends \ArrayObject
{
private $cache;
public function __construct(\Doctrine\Common\Cache\Cache $cache, array $data = array())
{
$this->cache = $cache;
parent::__construct($data, static::ARRAY_AS_PROPS);
}
public function offsetExists($id)
{
return $this->cache->contains($id);
}
public function offsetGet($id)
{
return $this->cache->fetch($id);
}
public function offsetSet($id, $data)
{
return $this->cache->save($id, $data);
}
public function offsetUnset($id)
{
return $this->cache->delete($id);
}
public function __invoke(array $data)
{
foreach ($data as $key => $value) {
$this[$key] = $value;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment