CacheAdapterEAccelerator.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. class LtCacheAdapterEAccelerator implements LtCacheAdapter
  3. {
  4. public function connect($hostConf)
  5. {
  6. return true;
  7. }
  8. public function add($key, $value, $ttl=0, $tableName, $connectionResource)
  9. {
  10. $value = serialize($value); //eAccelerator doesn't serialize object
  11. return eaccelerator_put($this->getRealKey($tableName, $key), $value, $ttl);
  12. }
  13. public function del($key, $tableName, $connectionResource)
  14. {
  15. return eaccelerator_rm($this->getRealKey($tableName, $key));
  16. }
  17. public function get($key, $tableName, $connectionResource)
  18. {
  19. $value = eaccelerator_get($this->getRealKey($tableName, $key));
  20. if (!empty($value))
  21. {
  22. return unserialize($value);
  23. }
  24. else
  25. {
  26. return false;
  27. }
  28. }
  29. public function update($key, $value, $ttl = 0, $tableName, $connectionResource)
  30. {
  31. if ($this->del($key, $tableName, $connectionResource))
  32. {
  33. return $this->add($key, $value, $ttl, $tableName, $connectionResource);
  34. }
  35. else
  36. {
  37. return false;
  38. }
  39. }
  40. protected function getRealKey($tableName, $key)
  41. {
  42. return $tableName . "-" . $key;
  43. }
  44. }