WinCacheCache.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. namespace Doctrine\Common\Cache;
  3. use function count;
  4. use function is_array;
  5. use function wincache_ucache_clear;
  6. use function wincache_ucache_delete;
  7. use function wincache_ucache_exists;
  8. use function wincache_ucache_get;
  9. use function wincache_ucache_info;
  10. use function wincache_ucache_meminfo;
  11. use function wincache_ucache_set;
  12. /**
  13. * WinCache cache provider.
  14. *
  15. * @link www.doctrine-project.org
  16. */
  17. class WinCacheCache extends CacheProvider
  18. {
  19. /**
  20. * {@inheritdoc}
  21. */
  22. protected function doFetch($id)
  23. {
  24. return wincache_ucache_get($id);
  25. }
  26. /**
  27. * {@inheritdoc}
  28. */
  29. protected function doContains($id)
  30. {
  31. return wincache_ucache_exists($id);
  32. }
  33. /**
  34. * {@inheritdoc}
  35. */
  36. protected function doSave($id, $data, $lifeTime = 0)
  37. {
  38. return wincache_ucache_set($id, $data, $lifeTime);
  39. }
  40. /**
  41. * {@inheritdoc}
  42. */
  43. protected function doDelete($id)
  44. {
  45. return wincache_ucache_delete($id);
  46. }
  47. /**
  48. * {@inheritdoc}
  49. */
  50. protected function doFlush()
  51. {
  52. return wincache_ucache_clear();
  53. }
  54. /**
  55. * {@inheritdoc}
  56. */
  57. protected function doFetchMultiple(array $keys)
  58. {
  59. return wincache_ucache_get($keys);
  60. }
  61. /**
  62. * {@inheritdoc}
  63. */
  64. protected function doSaveMultiple(array $keysAndValues, $lifetime = 0)
  65. {
  66. $result = wincache_ucache_set($keysAndValues, null, $lifetime);
  67. return empty($result);
  68. }
  69. /**
  70. * {@inheritdoc}
  71. */
  72. protected function doDeleteMultiple(array $keys)
  73. {
  74. $result = wincache_ucache_delete($keys);
  75. return is_array($result) && count($result) !== count($keys);
  76. }
  77. /**
  78. * {@inheritdoc}
  79. */
  80. protected function doGetStats()
  81. {
  82. $info = wincache_ucache_info();
  83. $meminfo = wincache_ucache_meminfo();
  84. return [
  85. Cache::STATS_HITS => $info['total_hit_count'],
  86. Cache::STATS_MISSES => $info['total_miss_count'],
  87. Cache::STATS_UPTIME => $info['total_cache_uptime'],
  88. Cache::STATS_MEMORY_USAGE => $meminfo['memory_total'],
  89. Cache::STATS_MEMORY_AVAILABLE => $meminfo['memory_free'],
  90. ];
  91. }
  92. }