GoogleGAL_Cache_Apc

A persistent storage class based on the APC cache, which is not really very persistent, as soon as you restart your web server the storage will be wiped, however for debugging and/or speed it can be useful, and cache is a lot cheaper then storage.

Defined (1)

The class is defined in the following location(s).

/core/Google/Cache/Apc.php  
  1. class GoogleGAL_Cache_Apc extends GoogleGAL_Cache_Abstract 
  2. /** 
  3. * @var GoogleGAL_Client the current client 
  4. */ 
  5. private $client; 
  6.  
  7. public function __construct(GoogleGAL_Client $client) 
  8. if (! function_exists('apc_add') ) { 
  9. $error = "Apc functions not available"; 
  10.  
  11. $client->getLogger()->error($error); 
  12. throw new GoogleGAL_Cache_Exception($error); 
  13.  
  14. $this->client = $client; 
  15.  
  16. /** 
  17. * @inheritDoc 
  18. */ 
  19. public function get($key, $expiration = false) 
  20. $ret = apc_fetch($key); 
  21. if ($ret === false) { 
  22. $this->client->getLogger()->debug( 
  23. 'APC cache miss',  
  24. array('key' => $key) 
  25. ); 
  26. return false; 
  27. if (is_numeric($expiration) && (time() - $ret['time'] > $expiration)) { 
  28. $this->client->getLogger()->debug( 
  29. 'APC cache miss (expired)',  
  30. array('key' => $key, 'var' => $ret) 
  31. ); 
  32. $this->delete($key); 
  33. return false; 
  34.  
  35. $this->client->getLogger()->debug( 
  36. 'APC cache hit',  
  37. array('key' => $key, 'var' => $ret) 
  38. ); 
  39.  
  40. return $ret['data']; 
  41.  
  42. /** 
  43. * @inheritDoc 
  44. */ 
  45. public function set($key, $value) 
  46. $var = array('time' => time(), 'data' => $value); 
  47. $rc = apc_store($key, $var); 
  48.  
  49. if ($rc == false) { 
  50. $this->client->getLogger()->error( 
  51. 'APC cache set failed',  
  52. array('key' => $key, 'var' => $var) 
  53. ); 
  54. throw new GoogleGAL_Cache_Exception("Couldn't store data"); 
  55.  
  56. $this->client->getLogger()->debug( 
  57. 'APC cache set',  
  58. array('key' => $key, 'var' => $var) 
  59. ); 
  60.  
  61. /** 
  62. * @inheritDoc 
  63. * @param String $key 
  64. */ 
  65. public function delete($key) 
  66. $this->client->getLogger()->debug( 
  67. 'APC cache delete',  
  68. array('key' => $key) 
  69. ); 
  70. apc_delete($key);