-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
30898fe
commit ce68cb7
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,12 @@ class Restrictions { | |
*/ | ||
public $restrictions; | ||
|
||
/** | ||
* Simple internal request based cache. | ||
* | ||
* @var array<string,mixed> | ||
*/ | ||
private $restrictions_cache; | ||
|
||
/** | ||
* Get a list of all restrictions. | ||
|
@@ -191,6 +197,60 @@ public function get_cache_key( $post_id = null ) { | |
return apply_filters( 'content_control/get_cache_key', $cache_key, $post_id, $user_id, $context ); | ||
} | ||
|
||
/** | ||
* Get from cache. | ||
* | ||
* @param string $cache_key Cache key. | ||
* | ||
* @return mixed|null | ||
*/ | ||
public function get_from_cache( $cache_key ) { | ||
/** | ||
* Allow preloading from cache. | ||
* | ||
* @param mixed|null $cache Cache. | ||
* @param string $cache_key Cache key. | ||
* @param Restrictions $this Restrictions instance. | ||
* | ||
* @return mixed|null | ||
* | ||
* @since 2.4.0 | ||
*/ | ||
$cache = apply_filters( 'content_control/get_restrictions_from_cache', null, $cache_key, $this ); | ||
Check failure on line 219 in classes/Services/Restrictions.php GitHub Actions / PHP Static Analysis
Check failure on line 219 in classes/Services/Restrictions.php GitHub Actions / PHP Static Analysis
|
||
|
||
if ( $cache ) { | ||
return $cache; | ||
} | ||
|
||
return $this->restrictions_cache[ $cache_key ] ?? null; | ||
} | ||
|
||
/** | ||
* Set in cache. | ||
* | ||
* @param string $cache_key Cache key. | ||
* @param mixed $value Value to set. | ||
* | ||
* @return void | ||
*/ | ||
public function set_in_cache( $cache_key, $value ) { | ||
$this->restrictions_cache[ $cache_key ] = $value; | ||
|
||
/** | ||
* Filter the cache. | ||
* | ||
* @param array<string,mixed> $cache Cache. | ||
* @param string $cache_key Cache key. | ||
* @param Restrictions $this Restrictions instance. | ||
* | ||
* @return array<string,mixed> | ||
* | ||
* @since 2.4.0 | ||
*/ | ||
do_action( 'content_control/set_restrictions_in_cache', $cache_key, $value, $this ); | ||
Check failure on line 250 in classes/Services/Restrictions.php GitHub Actions / PHP Static Analysis
|
||
} | ||
|
||
|
||
/** | ||
* Get all applicable restrictions for the current post. | ||
* | ||
|