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

89 lines 1.5 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 *
9 * @since 1.7
10 */
11 class PLL_Cache {
12 /**
13 * Current site id.
14 *
15 * @var int
16 */
17 protected $blog_id;
18
19 /**
20 * The cache container.
21 *
22 * @var array
23 */
24 protected $cache = array();
25
26 /**
27 * Constructor.
28 *
29 * @since 1.7
30 */
31 public function __construct() {
32 $this->blog_id = get_current_blog_id();
33 add_action( 'switch_blog', array( $this, 'switch_blog' ) );
34 }
35
36 /**
37 * Called when switching blog.
38 *
39 * @since 1.7
40 *
41 * @param int $new_blog_id New blog ID.
42 * @return void
43 */
44 public function switch_blog( $new_blog_id ) {
45 $this->blog_id = $new_blog_id;
46 }
47
48 /**
49 * Add a value in cache.
50 *
51 * @since 1.7
52 *
53 * @param string $key Cache key.
54 * @param mixed $data The value to add to the cache.
55 * @return void
56 */
57 public function set( $key, $data ) {
58 $this->cache[ $this->blog_id ][ $key ] = $data;
59 }
60
61 /**
62 * Get value from cache.
63 *
64 * @since 1.7
65 *
66 * @param string $key Cache key.
67 * @return mixed
68 */
69 public function get( $key ) {
70 return isset( $this->cache[ $this->blog_id ][ $key ] ) ? $this->cache[ $this->blog_id ][ $key ] : false;
71 }
72
73 /**
74 * Clean the cache (for this blog only).
75 *
76 * @since 1.7
77 *
78 * @param string $key Cache key.
79 * @return void
80 */
81 public function clean( $key = '' ) {
82 if ( empty( $key ) ) {
83 unset( $this->cache[ $this->blog_id ] );
84 } else {
85 unset( $this->cache[ $this->blog_id ][ $key ] );
86 }
87 }
88 }
89