PluginProbe
Polylang / 2.2.5
Polylang v2.2.5
3.8.9 3.8.8 3.8.7 3.8.6 3.8.5 3.8.4 3.8.3 2.7 2.7.0.1 2.7.1 2.7.2 2.7.3 2.7.4 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.9 2.9.1 2.9.2 3.0 3.0.1 3.0.2 3.0.3 All 233 releases
polylang / include / cache.php

cache.php in Polylang 2.2.5, at include/cache.php

73 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * An extremely simple non persistent cache system
5 * not as fast as using directly an array but more readable
6 *
7 * @since 1.7
8 */
9 class PLL_Cache {
10 protected $blog_id, $cache;
11
12 /**
13 * Constructor
14 *
15 * @since 1.7
16 */
17 public function __construct() {
18 $this->blog_id = get_current_blog_id();
19 add_action( 'switch_blog', array( $this, 'switch_blog' ) );
20 }
21
22 /**
23 * Called when switching blog
24 *
25 * @since 1.7
26 *
27 * @param int $new_blog
28 */
29 public function switch_blog( $new_blog ) {
30 $this->blog_id = $new_blog;
31 }
32
33 /**
34 * Add a value in cache
35 *
36 * @since 1.7
37 *
38 * @param string $key
39 * @param mixed $data
40 */
41 public function set( $key, $data ) {
42 $this->cache[ $this->blog_id ][ $key ] = $data;
43 }
44
45 /**
46 * Get value from cache
47 *
48 * @since 1.7
49 *
50 * @param string $key
51 * @return mixed $data
52 */
53 public function get( $key ) {
54 return isset( $this->cache[ $this->blog_id ][ $key ] ) ? $this->cache[ $this->blog_id ][ $key ] : false;
55 }
56
57 /**
58 * Clean the cache (for this blog only)
59 *
60 * @since 1.7
61 *
62 * @param string $key
63 */
64 public function clean( $key = '' ) {
65 if ( empty( $key ) ) {
66 unset( $this->cache[ $this->blog_id ] );
67 }
68 else {
69 unset( $this->cache[ $this->blog_id ][ $key ] );
70 }
71 }
72 }
73