WinCacheCache.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /*
  3. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  4. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  5. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  6. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  7. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  8. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  9. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  10. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  11. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  12. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  13. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14. *
  15. * This software consists of voluntary contributions made by many individuals
  16. * and is licensed under the LGPL. For more information, see
  17. * <http://www.doctrine-project.org>.
  18. */
  19. namespace Doctrine\Common\Cache;
  20. /**
  21. * WinCache cache provider.
  22. *
  23. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  24. * @link www.doctrine-project.org
  25. * @since 2.2
  26. * @author Benjamin Eberlei <kontakt@beberlei.de>
  27. * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
  28. * @author Jonathan Wage <jonwage@gmail.com>
  29. * @author Roman Borschel <roman@code-factory.org>
  30. * @author David Abdemoulaie <dave@hobodave.com>
  31. */
  32. class WincacheCache extends CacheProvider
  33. {
  34. /**
  35. * {@inheritdoc}
  36. */
  37. protected function doFetch($id)
  38. {
  39. return wincache_ucache_get($id);
  40. }
  41. /**
  42. * {@inheritdoc}
  43. */
  44. protected function doContains($id)
  45. {
  46. return wincache_ucache_exists($id);
  47. }
  48. /**
  49. * {@inheritdoc}
  50. */
  51. protected function doSave($id, $data, $lifeTime = 0)
  52. {
  53. return (bool) wincache_ucache_set($id, $data, (int) $lifeTime);
  54. }
  55. /**
  56. * {@inheritdoc}
  57. */
  58. protected function doDelete($id)
  59. {
  60. return wincache_ucache_delete($id);
  61. }
  62. /**
  63. * {@inheritdoc}
  64. */
  65. protected function doFlush()
  66. {
  67. return wincache_ucache_clear();
  68. }
  69. /**
  70. * {@inheritdoc}
  71. */
  72. protected function doGetStats()
  73. {
  74. $info = wincache_ucache_info();
  75. $meminfo= wincache_ucache_meminfo();
  76. return array(
  77. Cache::STATS_HITS => $info['total_hit_count'],
  78. Cache::STATS_MISSES => $info['total_miss_count'],
  79. Cache::STATS_UPTIME => $info['total_cache_uptime'],
  80. Cache::STATS_MEMORY_USAGE => $meminfo['memory_total'],
  81. Cache::STATS_MEMORY_AVAILIABLE => $meminfo['memory_free'],
  82. );
  83. }
  84. }