PLL_Cache

An extremely simple non persistent cache system not as fast as using directly an array but more readable.

Defined (1)

The class is defined in the following location(s).

/include/cache.php  
  1. class PLL_Cache { 
  2. protected $blog_id, $cache; 
  3.  
  4. /** 
  5. * constructor 
  6. * @since 1.7 
  7. */ 
  8. public function __construct() { 
  9. $this->blog_id = get_current_blog_id(); 
  10. add_action( 'switch_blog', array( $this, 'switch_blog' ) ); 
  11.  
  12. /** 
  13. * called when switching blog 
  14. * @since 1.7 
  15. * @param int $new_blog 
  16. */ 
  17. public function switch_blog( $new_blog ) { 
  18. $this->blog_id = $new_blog; 
  19.  
  20. /** 
  21. * add a value in cache 
  22. * @since 1.7 
  23. * @param string $key 
  24. * @param mixed $data 
  25. */ 
  26. public function set( $key, $data ) { 
  27. $this->cache[ $this->blog_id ][ $key ] = $data; 
  28.  
  29. /** 
  30. * get value from cache 
  31. * @since 1.7 
  32. * @param string $key 
  33. * @return mixed $data 
  34. */ 
  35. public function get( $key ) { 
  36. return isset( $this->cache[ $this->blog_id ][ $key ] ) ? $this->cache[ $this->blog_id ][ $key ] : false; 
  37.  
  38. /** 
  39. * clean the cache (for this blog only) 
  40. * @since 1.7 
  41. */ 
  42. public function clean( $key = '' ) { 
  43. if ( empty( $key ) ) { 
  44. unset( $this->cache[ $this->blog_id ] ); 
  45. else { 
  46. unset( $this->cache[ $this->blog_id ][ $key ] );