Cache_apc.php 3.2 KB

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