Cache_apc.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. /**
  3. * CodeIgniter
  4. *
  5. * An open source application development framework for PHP 5.1.6 or newer
  6. *
  7. * @package CodeIgniter
  8. * @author ExpressionEngine Dev Team
  9. * @copyright Copyright (c) 2006 - 2012 EllisLab, Inc.
  10. * @license http://codeigniter.com/user_guide/license.html
  11. * @link http://codeigniter.com
  12. * @since Version 2.0
  13. * @filesource
  14. */
  15. // ------------------------------------------------------------------------
  16. /**
  17. * CodeIgniter APC Caching Class
  18. *
  19. * @package CodeIgniter
  20. * @subpackage Libraries
  21. * @category Core
  22. * @author ExpressionEngine Dev Team
  23. * @link
  24. */
  25. class CI_Cache_apc extends CI_Driver {
  26. /**
  27. * Get
  28. *
  29. * Look for a value in the cache. If it exists, return the data
  30. * if not, return FALSE
  31. *
  32. * @param string
  33. * @return mixed value that is stored/FALSE on failure
  34. */
  35. public function get($id)
  36. {
  37. $data = apc_fetch($id);
  38. return (is_array($data)) ? $data[0] : FALSE;
  39. }
  40. // ------------------------------------------------------------------------
  41. /**
  42. * Cache Save
  43. *
  44. * @param string Unique Key
  45. * @param mixed Data to store
  46. * @param int Length of time (in seconds) to cache the data
  47. *
  48. * @return boolean true on success/false on failure
  49. */
  50. public function save($id, $data, $ttl = 60)
  51. {
  52. return apc_store($id, array($data, time(), $ttl), $ttl);
  53. }
  54. // ------------------------------------------------------------------------
  55. /**
  56. * Delete from Cache
  57. *
  58. * @param mixed unique identifier of the item in the cache
  59. * @param boolean true on success/false on failure
  60. */
  61. public function delete($id)
  62. {
  63. return apc_delete($id);
  64. }
  65. // ------------------------------------------------------------------------
  66. /**
  67. * Clean the cache
  68. *
  69. * @return boolean false on failure/true on success
  70. */
  71. public function clean()
  72. {
  73. return apc_clear_cache('user');
  74. }
  75. // ------------------------------------------------------------------------
  76. /**
  77. * Cache Info
  78. *
  79. * @param string user/filehits
  80. * @return mixed array on success, false on failure
  81. */
  82. public function cache_info($type = NULL)
  83. {
  84. return apc_cache_info($type);
  85. }
  86. // ------------------------------------------------------------------------
  87. /**
  88. * Get Cache Metadata
  89. *
  90. * @param mixed key to get cache metadata on
  91. * @return mixed array on success/false on failure
  92. */
  93. public function get_metadata($id)
  94. {
  95. $stored = apc_fetch($id);
  96. if (count($stored) !== 3)
  97. {
  98. return FALSE;
  99. }
  100. list($data, $time, $ttl) = $stored;
  101. return array(
  102. 'expire' => $time + $ttl,
  103. 'mtime' => $time,
  104. 'data' => $data
  105. );
  106. }
  107. // ------------------------------------------------------------------------
  108. /**
  109. * is_supported()
  110. *
  111. * Check to see if APC is available on this system, bail if it isn't.
  112. */
  113. public function is_supported()
  114. {
  115. if ( ! extension_loaded('apc') OR ini_get('apc.enabled') != "1")
  116. {
  117. log_message('error', 'The APC PHP extension must be loaded to use APC Cache.');
  118. return FALSE;
  119. }
  120. return TRUE;
  121. }
  122. // ------------------------------------------------------------------------
  123. }
  124. // End Class
  125. /* End of file Cache_apc.php */
  126. /* Location: ./system/libraries/Cache/drivers/Cache_apc.php */