Skip to content

Instantly share code, notes, and snippets.

@sobstel
Created May 13, 2012 07:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sobstel/2686852 to your computer and use it in GitHub Desktop.
Save sobstel/2686852 to your computer and use it in GitHub Desktop.
Doctrine\Common\Cache\CacheProvider performance-aware adapter
<?php
class DoctrineCacheAdapter extends \Doctrine\Common\Cache\CacheProvider {
private $cache_driver;
public function __construct($cache_driver) {
$this->cache_driver = $cache_driver;
}
public function getCacheDriver() {
return $this->cache_driver;
}
public function setNamespace($namespace) {
throw new Exception('DoctrineCacheAdapter::setNamespace() not supported');
}
public function getNamespace() {
throw new Exception('DoctrineCacheAdapter::getNamespace() not supported');
}
public function fetch($id) {
return $this->doFetch($id);
}
public function contains($id) {
return $this->doContains($id);
}
public function save($id, $data, $lifeTime = 0) {
return $this->doSave($id, $data, $lifeTime);
}
public function delete($id) {
return $this->doDelete($id);
}
public function getStats() {
throw new Exception('DoctrineCacheAdapter::getStats() not supported');
}
public function flushAll() {
throw new Exception('DoctrineCacheAdapter::flushAll() not supported');
}
public function deleteAll() {
throw new Exception('DoctrineCacheAdapter::deleteAll() not supported');
}
protected function doFetch($id) {
return $this->getCacheDriver()->get($id);
}
protected function doContains($id) {
return ($this->getCacheDriver()->get($id) !== false);
}
protected function doSave($id, $data, $lifeTime = false) {
return $this->getCacheDriver()->set($id, $data, $lifeTime);
}
protected function doDelete($id) {
return $this->getCacheDriver()->getStore()->delete($id);
}
protected function doFlush() {
throw new Exception('DoctrineCacheAdapter::doFlush() not supported');
}
protected function doGetStats() {
throw new Exception('DoctrineCacheAdapter::doGetStats() not supported');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment