You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.3 KiB

13 years ago
13 years ago
13 years ago
13 years ago
  1. <?php
  2. /**
  3. * @copyright NetMonsters <team@netmonsters.ru>
  4. * @link http://netmonsters.ru
  5. * @package Majestic
  6. * @subpackage Cache
  7. * @since 2010-03-10
  8. */
  9. class CacheKey
  10. {
  11. /**
  12. * @var Cache
  13. */
  14. protected $cacher;
  15. /**
  16. * @var CacheKey
  17. */
  18. protected $key;
  19. protected $expire = 0;
  20. /**
  21. * @param Cacher $cacher
  22. * @param string $key
  23. * @param mixed $params
  24. * @param int $expire
  25. * @return CacheKey
  26. */
  27. public function __construct($cacher, $key, $params = array(), $expire = 0)
  28. {
  29. $this->cacher = $cacher;
  30. $this->key = $key;
  31. if ($params) {
  32. $params = (is_array($params)) ? implode('|', $params) : $params;
  33. $this->key = $key . '_' . $params;
  34. }
  35. $this->expire = $expire;
  36. }
  37. protected function getExpire()
  38. {
  39. return $this->expire;
  40. }
  41. /**
  42. * @param int $expire
  43. */
  44. public function setExpire($expire)
  45. {
  46. $this->expire = $expire;
  47. }
  48. public function get()
  49. {
  50. return $this->cacher->get($this->key);
  51. }
  52. /**
  53. * @param mixed $value
  54. * @return bool
  55. */
  56. public function set($value)
  57. {
  58. return $this->cacher->set($this->key, $value, $this->expire);
  59. }
  60. public function del()
  61. {
  62. return $this->cacher->del($this->key);
  63. }
  64. }