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.

74 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 Cacher
  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. */
  57. public function set($value)
  58. {
  59. return $this->cacher->set($this->key, $value, $this->expire);
  60. }
  61. public function del()
  62. {
  63. return $this->cacher->del($this->key);
  64. }
  65. }