CacheAdapterMemcached.php 968 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. class LtCacheAdapterMemcached implements LtCacheAdapter
  3. {
  4. public function connect($hostConf)
  5. {
  6. $connectionResource = new Memcached();
  7. $connectionResource->addServer($hostConf["host"], $hostConf["port"]);
  8. return $connectionResource;
  9. }
  10. public function add($key, $value, $ttl=0, $tableName, $connectionResource)
  11. {
  12. return $connectionResource->add($this->getRealKey($tableName, $key), $value, $ttl);
  13. }
  14. public function del($key, $tableName, $connectionResource)
  15. {
  16. return $connectionResource->delete($this->getRealKey($tableName, $key));
  17. }
  18. public function get($key, $tableName, $connectionResource)
  19. {
  20. return $connectionResource->get($this->getRealKey($tableName, $key));
  21. }
  22. public function update($key, $value, $ttl = 0, $tableName, $connectionResource)
  23. {
  24. return $connectionResource->replace($this->getRealKey($tableName, $key), $value, $ttl);
  25. }
  26. protected function getRealKey($tableName, $key)
  27. {
  28. return $tableName . "-" . $key;
  29. }
  30. }