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