API
4 months ago
Admin
4 months ago
Blocks
4 months ago
CLI
4 months ago
Container
4 months ago
Data
4 months ago
Integrations
4 months ago
REST
4 months ago
Theme
4 months ago
Tools
4 months ago
WP
4 months ago
Whatsit
4 months ago
Config_Handler.php
4 months ago
Integration.php
4 months ago
Permissions.php
4 months ago
Pod_Manager.php
4 months ago
Service_Provider.php
4 months ago
Service_Provider_Base.php
4 months ago
Static_Cache.php
4 months ago
Whatsit.php
4 months ago
Wisdom_Tracker.php
4 months ago
Static_Cache.php
112 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Pods; |
| 4 | |
| 5 | // Don't load directly. |
| 6 | if ( ! defined( 'ABSPATH' ) ) { |
| 7 | die( '-1' ); |
| 8 | } |
| 9 | |
| 10 | /** |
| 11 | * Static cache class used for storing on-page cached vars but not storing them into the object cache |
| 12 | * with support for multisite. Each site has their own cache. |
| 13 | * |
| 14 | * @since 2.8 |
| 15 | */ |
| 16 | class Static_Cache { |
| 17 | |
| 18 | /** |
| 19 | * The cache array. |
| 20 | * |
| 21 | * @since 2.8 |
| 22 | * |
| 23 | * @var array |
| 24 | */ |
| 25 | protected static $cache = []; |
| 26 | |
| 27 | /** |
| 28 | * Get the cache value from the cache. |
| 29 | * |
| 30 | * @since 2.8 |
| 31 | * |
| 32 | * @param string $key The cache key. |
| 33 | * @param string $group The cache group. |
| 34 | * |
| 35 | * @return mixed|false The cache value from the cache. |
| 36 | */ |
| 37 | public function get( $key, $group = 'global' ) { |
| 38 | $blog_id = get_current_blog_id(); |
| 39 | |
| 40 | if ( ! isset( self::$cache[ $blog_id ][ $group ][ $key ] ) ) { |
| 41 | return false; |
| 42 | } |
| 43 | |
| 44 | return self::$cache[ $blog_id ][ $group ][ $key ]; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Set the cache value in the cache. |
| 49 | * |
| 50 | * @since 2.8 |
| 51 | * |
| 52 | * @param string $key The cache key. |
| 53 | * @param mixed $value The cache value. |
| 54 | * @param string $group The cache group. |
| 55 | */ |
| 56 | public function set( $key, $value, $group = 'global' ) { |
| 57 | $blog_id = get_current_blog_id(); |
| 58 | |
| 59 | if ( ! isset( self::$cache[ $blog_id ] ) ) { |
| 60 | self::$cache[ $blog_id ] = []; |
| 61 | } |
| 62 | |
| 63 | if ( ! isset( self::$cache[ $blog_id ][ $group ] ) ) { |
| 64 | self::$cache[ $blog_id ][ $group ] = []; |
| 65 | } |
| 66 | |
| 67 | self::$cache[ $blog_id ][ $group ][ $key ] = $value; |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Delete the cache value from the cache. |
| 72 | * |
| 73 | * @since 2.8 |
| 74 | * |
| 75 | * @param string $key The cache key. |
| 76 | * @param string $group The cache group. |
| 77 | */ |
| 78 | public function delete( $key, $group = 'global' ) { |
| 79 | $blog_id = get_current_blog_id(); |
| 80 | |
| 81 | if ( ! isset( self::$cache[ $blog_id ][ $group ][ $key ] ) ) { |
| 82 | return false; |
| 83 | } |
| 84 | |
| 85 | unset( self::$cache[ $blog_id ][ $group ][ $key ] ); |
| 86 | |
| 87 | return true; |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Flush the cache. |
| 92 | * |
| 93 | * @since 2.8 |
| 94 | * |
| 95 | * @param string $group The cache group. |
| 96 | */ |
| 97 | public function flush( $group = null ) { |
| 98 | $blog_id = get_current_blog_id(); |
| 99 | |
| 100 | if ( $group ) { |
| 101 | if ( ! isset( self::$cache[ $blog_id ] ) ) { |
| 102 | self::$cache[ $blog_id ] = []; |
| 103 | } |
| 104 | |
| 105 | self::$cache[ $blog_id ][ $group ] = []; |
| 106 | } else { |
| 107 | self::$cache[ $blog_id ] = []; |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | } |
| 112 |