CacheHandle.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. class LtCacheHandle
  3. {
  4. public $configHandle;
  5. public $group;
  6. public $node;
  7. public $role = "master";
  8. public $connectionManager;
  9. public $connectionResource;
  10. protected $connectionAdapter;
  11. public function __construct()
  12. {
  13. }
  14. public function init()
  15. {
  16. $this->connectionManager = new LtCacheConnectionManager;
  17. $this->connectionManager->configHandle =$this->configHandle;
  18. }
  19. public function add($key, $value, $ttl = 0, $tableName)
  20. {
  21. $this->initConnection();
  22. return $this->connectionAdapter->add($key, $value, $ttl, $tableName, $this->connectionResource);
  23. }
  24. public function del($key, $tableName)
  25. {
  26. $this->initConnection();
  27. return $this->connectionAdapter->del($key, $tableName, $this->connectionResource);
  28. }
  29. public function get($key, $tableName)
  30. {
  31. $this->initConnection();
  32. return $this->connectionAdapter->get($key, $tableName, $this->connectionResource);
  33. }
  34. public function update($key, $value, $ttl = 0, $tableName)
  35. {
  36. $this->initConnection();
  37. return $this->connectionAdapter->update($key, $value, $ttl, $tableName, $this->connectionResource);
  38. }
  39. protected function initConnection()
  40. {
  41. $connectionInfo = $this->connectionManager->getConnection($this->group, $this->node, $this->role);
  42. $this->connectionAdapter = $connectionInfo["connectionAdapter"];
  43. $this->connectionResource = $connectionInfo["connectionResource"];
  44. }
  45. }