PluginProbe
Polylang / 3.3.3
Polylang v3.3.3
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 3.3.3, at include/cache.php

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