Basic.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /*
  3. Copyright (c) 2012, Open Source Solutions Limited, Dublin, Ireland
  4. All rights reserved.
  5. Contact: Barry O'Donovan - barry (at) opensolutions (dot) ie
  6. http://www.opensolutions.ie/
  7. This file is part of the OSS_SNMP package.
  8. Redistribution and use in source and binary forms, with or without
  9. modification, are permitted provided that the following conditions are met:
  10. * Redistributions of source code must retain the above copyright
  11. notice, this list of conditions and the following disclaimer.
  12. * Redistributions in binary form must reproduce the above copyright
  13. notice, this list of conditions and the following disclaimer in the
  14. documentation and/or other materials provided with the distribution.
  15. * Neither the name of Open Source Solutions Limited nor the
  16. names of its contributors may be used to endorse or promote products
  17. derived from this software without specific prior written permission.
  18. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  19. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  22. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  25. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. namespace OSS\Cache;
  30. /**
  31. * basic (array) cache implementation
  32. *
  33. * @copyright Copyright (c) 2012, Open Source Solutions Limited, Dublin, Ireland
  34. * @author Barry O'Donovan <barry@opensolutions.ie>
  35. */
  36. class Basic extends \OSS\Cache
  37. {
  38. /**
  39. * An array to store results - a temporary cache
  40. * @var array An array to store results - a temporary cache
  41. */
  42. protected $_cache;
  43. /**
  44. * Cache constructor.
  45. *
  46. * For basic cache, takes no parameters.
  47. *
  48. * @return \OSS\Cache\Basic An instance of the cache ($this) for fluent interfaces
  49. */
  50. public function __construct()
  51. {
  52. $_cache = array();
  53. return $this;
  54. }
  55. /**
  56. * Load a named value from the cache (or null if not present)
  57. *
  58. * @param string $var The name of the value to load
  59. * @return mixed|null The value from the cache or null
  60. */
  61. public function load( $var )
  62. {
  63. if( isset( $this->_cache[ $var ] ) )
  64. return $this->_cache[ $var ];
  65. return null;
  66. }
  67. /**
  68. * Save a named value to the cache
  69. *
  70. * @param string $var The name of the value to save
  71. * @param mixed $val The value to save
  72. * @return mixed The value (as passed)
  73. */
  74. public function save( $var, $val )
  75. {
  76. return $this->_cache[ $var ] = $val;
  77. }
  78. /**
  79. * Clear a named value from the cache
  80. *
  81. * @param string $var The name of the value to clear
  82. */
  83. public function clear( $var )
  84. {
  85. if( isset( $this->_cache[ $var ] ) )
  86. unset( $this->_cache[ $var ] );
  87. }
  88. /**
  89. * Clear all values from the cache
  90. *
  91. */
  92. public function clearAll()
  93. {
  94. $this->_cache = array();
  95. }
  96. }