CacheAdapterMemcache.php 908 B

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