Brak opisu

cache.php 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. /*******************************************************************************
  3. * Copyright (c) 2019, Code Atlantic LLC
  4. ******************************************************************************/
  5. if ( ! defined( 'ABSPATH' ) ) {
  6. exit; // Exit if accessed directly
  7. }
  8. /**
  9. * Add a cache key via PUM Cache.
  10. *
  11. * @param $key
  12. * @param $data
  13. * @param string $group
  14. *
  15. * @return bool
  16. */
  17. function pum_cache_add( $key, $data, $group = '' ) {
  18. return PUM_Utils_Cache::add( $key, $data, $group );
  19. }
  20. /**
  21. * Set a cache key via PUM Cache.
  22. *
  23. * @param $key
  24. * @param $data
  25. * @param string $group
  26. *
  27. * @return bool
  28. */
  29. function pum_cache_set( $key, $data, $group = '' ) {
  30. return PUM_Utils_Cache::set( $key, $data, $group );
  31. }
  32. /**
  33. * Replace a cache key via PUM Cache.
  34. *
  35. * @param $key
  36. * @param $data
  37. * @param string $group
  38. *
  39. * @return bool
  40. */
  41. function pum_cache_replace( $key, $data, $group = '' ) {
  42. return PUM_Utils_Cache::replace( $key, $data, $group );
  43. }
  44. /**
  45. * Get a cache key via PUM Cache.
  46. *
  47. * @param $key
  48. * @param string $group
  49. * @param bool $force
  50. * @param null $found
  51. *
  52. * @return bool|mixed
  53. */
  54. function pum_cache_get( $key, $group = '', $force = false, &$found = null ) {
  55. return PUM_Utils_Cache::get( $key, $group, $force, $found );
  56. }
  57. /**
  58. * Delete a cache key via PUM Cache.
  59. *
  60. * @param $key
  61. * @param string $group
  62. *
  63. * @return bool
  64. */
  65. function pum_cache_delete( $key, $group = '' ) {
  66. return PUM_Utils_Cache::delete( $key, $group );
  67. }
  68. /**
  69. * Delete a cache group via PUM Cache.
  70. *
  71. * @param string $group
  72. *
  73. * @return bool
  74. */
  75. function pum_cache_delete_group( $group = '' ) {
  76. return PUM_Utils_Cache::delete_group( $group );
  77. }
  78. /**
  79. * Increase a numeric cache value by the offset.
  80. *
  81. * @param $key
  82. * @param int $offset
  83. * @param string $group
  84. *
  85. * @return bool|false|int
  86. */
  87. function pum_cache_incr( $key, $offset = 1, $group = '' ) {
  88. return PUM_Utils_Cache::incr( $key, $offset, $group );
  89. }
  90. /**
  91. * Decrease a numeric cache value by the offset.
  92. *
  93. * @param $key
  94. * @param int $offset
  95. * @param string $group
  96. *
  97. * @return bool|false|int
  98. */
  99. function pum_cache_decr( $key, $offset = 1, $group = '' ) {
  100. return PUM_Utils_Cache::decr( $key, $offset, $group );
  101. }
  102. /**
  103. * Gets the filterable timeout for a cache object by key.
  104. *
  105. * @param $key
  106. *
  107. * @return int
  108. */
  109. function pum_cache_timeout( $key ) {
  110. static $timeouts;
  111. if ( ! isset( $timeouts ) ) {
  112. $timeouts = apply_filters( 'pum_cache_timeouts', array() );
  113. }
  114. return isset( $timeouts[ $key ] ) ? $timeouts[ $key ] : 0;
  115. }