xpdowincache.class.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /*
  3. * Copyright 2010-2015 by MODX, LLC.
  4. *
  5. * This file is part of xPDO.
  6. *
  7. * xPDO is free software; you can redistribute it and/or modify it under the
  8. * terms of the GNU General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option) any later
  10. * version.
  11. *
  12. * xPDO is distributed in the hope that it will be useful, but WITHOUT ANY
  13. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  14. * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * xPDO; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
  18. * Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. /**
  21. * Provides a wincache-powered xPDOCache implementation.
  22. *
  23. * This requires the wincache extension for PHP, version 1.1.0 or later. Earlier versions
  24. * did not have user cache methods.
  25. *
  26. * @package xpdo
  27. * @subpackage cache
  28. */
  29. class xPDOWinCache extends xPDOCache {
  30. public function __construct(& $xpdo, $options = array()) {
  31. parent :: __construct($xpdo, $options);
  32. if (function_exists('wincache_ucache_info')) {
  33. $this->initialized = true;
  34. } else {
  35. $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "xPDOWinCache[{$this->key}]: Error creating wincache provider; xPDOWinCache requires the PHP wincache extension, version 1.1.0 or later.");
  36. }
  37. }
  38. public function add($key, $var, $expire= 0, $options= array()) {
  39. $added= wincache_ucache_add(
  40. $this->getCacheKey($key),
  41. $var,
  42. $expire
  43. );
  44. return $added;
  45. }
  46. public function set($key, $var, $expire= 0, $options= array()) {
  47. $set= wincache_ucache_set(
  48. $this->getCacheKey($key),
  49. $var,
  50. $expire
  51. );
  52. return $set;
  53. }
  54. public function replace($key, $var, $expire= 0, $options= array()) {
  55. $replaced = false;
  56. if (wincache_ucache_exists($key)) {
  57. $replaced= wincache_ucache_set(
  58. $this->getCacheKey($key),
  59. $var,
  60. $expire
  61. );
  62. }
  63. return $replaced;
  64. }
  65. public function delete($key, $options= array()) {
  66. $deleted = false;
  67. if (!isset($options['multiple_object_delete']) || empty($options['multiple_object_delete'])) {
  68. $deleted= wincache_ucache_delete($this->getCacheKey($key));
  69. } else {
  70. $deleted= $this->flush($options);
  71. }
  72. return $deleted;
  73. }
  74. public function get($key, $options= array()) {
  75. $value= wincache_ucache_get($this->getCacheKey($key));
  76. return $value;
  77. }
  78. public function flush($options= array()) {
  79. return wincache_ucache_clear();
  80. }
  81. }