PluginProbe
Polylang / 2.8.4
Polylang v2.8.4
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.8.4, at include/cache.php

76 lines 1.3 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 protected $blog_id, $cache;
14
15 /**
16 * Constructor
17 *
18 * @since 1.7
19 */
20 public function __construct() {
21 $this->blog_id = get_current_blog_id();
22 add_action( 'switch_blog', array( $this, 'switch_blog' ) );
23 }
24
25 /**
26 * Called when switching blog
27 *
28 * @since 1.7
29 *
30 * @param int $new_blog
31 */
32 public function switch_blog( $new_blog ) {
33 $this->blog_id = $new_blog;
34 }
35
36 /**
37 * Add a value in cache
38 *
39 * @since 1.7
40 *
41 * @param string $key
42 * @param mixed $data
43 */
44 public function set( $key, $data ) {
45 $this->cache[ $this->blog_id ][ $key ] = $data;
46 }
47
48 /**
49 * Get value from cache
50 *
51 * @since 1.7
52 *
53 * @param string $key
54 * @return mixed $data
55 */
56 public function get( $key ) {
57 return isset( $this->cache[ $this->blog_id ][ $key ] ) ? $this->cache[ $this->blog_id ][ $key ] : false;
58 }
59
60 /**
61 * Clean the cache (for this blog only)
62 *
63 * @since 1.7
64 *
65 * @param string $key
66 */
67 public function clean( $key = '' ) {
68 if ( empty( $key ) ) {
69 unset( $this->cache[ $this->blog_id ] );
70 }
71 else {
72 unset( $this->cache[ $this->blog_id ][ $key ] );
73 }
74 }
75 }
76