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.

75 lines
1.4 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. * @version SVN: $Id$
  9. * @filesource $URL$
  10. */
  11. class CacheKey
  12. {
  13. /**
  14. * @var Cache
  15. */
  16. protected $cacher;
  17. /**
  18. * @var CacheKey
  19. */
  20. protected $key;
  21. protected $expire = 0;
  22. /**
  23. * @param Cacher $cacher
  24. * @param string $key
  25. * @param mixed $params
  26. * @param int $expire
  27. * @return CacheKey
  28. */
  29. public function __construct($cacher, $key, $params = array(), $expire = 0)
  30. {
  31. $this->cacher = $cacher;
  32. $this->key = $key;
  33. if ($params) {
  34. $params = (is_array($params)) ? implode('|', $params) : $params;
  35. $this->key = $key . '_' . $params;
  36. }
  37. $this->expire = $expire;
  38. }
  39. protected function getExpire()
  40. {
  41. return $this->expire;
  42. }
  43. /**
  44. * @param int $expire
  45. */
  46. public function setExpire($expire)
  47. {
  48. $this->expire = $expire;
  49. }
  50. public function get()
  51. {
  52. return $this->cacher->get($this->key);
  53. }
  54. /**
  55. * @param mixed $value
  56. * @return bool
  57. */
  58. public function set($value)
  59. {
  60. return $this->cacher->set($this->key, $value, $this->expire);
  61. }
  62. public function del()
  63. {
  64. return $this->cacher->del($this->key);
  65. }
  66. }