Source for file Cache.class.php

Documentation is available at Cache.class.php

  1. <?php
  2. /**
  3. * @package harmoni.utilities
  4. *
  5. * @copyright Copyright &copy; 2005, Middlebury College
  6. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  7. *
  8. * @version $Id: Cache.class.php,v 1.3 2007/09/04 20:25:54 adamfranco Exp $
  9. */
  10.  
  11. define("CACHE_VARIABLE","__cache");
  12.  
  13. $_temp = CACHE_VARIABLE;
  14. $$_temp = array();
  15. unset($_temp);
  16.  
  17. /**
  18. * This class acts as a basic cache. It stores data in a multi-dimensional
  19. * associative array that is built at execution time to store any arbitrary data
  20. * by "filing".
  21. * @package harmoni.utilities
  22. * @copyright 2004
  23. * @version $Id: Cache.class.php,v 1.3 2007/09/04 20:25:54 adamfranco Exp $
  24. */
  25. class Cache {
  26.  
  27. function Cache() {
  28. die("<b>Cache is a static class - it should not be instantiated!</b>");
  29. }
  30. /**
  31. * Stores an object.
  32. * @param ref mixed $object Any variable that should be stored.
  33. * @param string $ident1 The first identifier for the object.
  34. * @param optional string $ident2,... Any number of additional identifiers.
  35. * @return void
  36. * @access public
  37. */
  38. function store($object, $ident1) {
  39. $string = '';
  40. $displayParts = array();
  41. for ($i=1; $i<func_num_args(); $i++) {
  42. $part = func_get_arg($i);
  43. $string .= "['$part']";
  44. $displayParts[] = $part;
  45. }
  46. $cache =$GLOBALS[CACHE_VARIABLE];
  47. $eval = '$bool = isset($cache'.$string.');';
  48. eval($eval);
  49. if ($bool) {
  50. throwError( new Error(
  51. "Cache - an item with identifyer <b>".implode(":",$displayParts)."</b> is already stored!","Cache",true));
  52. }
  53. $eval = '$cache'.$string.' =$object;';
  54. eval($eval);
  55. }
  56.  
  57. /**
  58. * Checks to see if we have any data stored under the given identifiers.
  59. * @param string $ident1 The first identifier for the object.
  60. * @param optional string $ident2,... Any number of additional identifiers.
  61. * @return boolean
  62. * @access public
  63. */
  64. function contains($ident1) {
  65. $string = '';
  66. for ($i=0; $i<func_num_args(); $i++) {
  67. $part = func_get_arg($i);
  68. $string .= "['$part']";
  69. $displayParts[] = $part;
  70. }
  71. $cache =$GLOBALS[CACHE_VARIABLE];
  72. $eval = '$bool = isset($cache'.$string.');';
  73. eval($eval);
  74. return $bool;
  75. }
  76. /**
  77. * Retrieves stored data specified by the given identifiers.
  78. * @param string $ident1 The first identifier for the object.
  79. * @param optional string $ident2,... Any number of additional identifiers.
  80. * @return ref mixed
  81. * @access public
  82. */
  83. function get($ident1) {
  84. $string = '';
  85. for ($i=0; $i<func_num_args(); $i++) {
  86. $part = func_get_arg($i);
  87. $string .= "['$part']";
  88. $displayParts[] = $part;
  89. }
  90. $cache =$GLOBALS[CACHE_VARIABLE];
  91. $eval = '$bool = isset($cache'.$string.');';
  92. eval($eval);
  93. if (!$bool) {
  94. throwError( new Error(
  95. "Cache - no item with identifyer <b>".implode(":",$displayParts)."</b> is stored!","Cache",true));
  96. }
  97. $eval = '$object =$cache'.$string.';';
  98. eval($eval);
  99. return $object;
  100. }
  101. }

Documentation generated on Wed, 19 Sep 2007 10:21:57 -0400 by phpDocumentor 1.3.0RC3