Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
ScssPhp\ScssPhp\Cache Class Reference

The scss cache manager. More...

Static Public Member Functions

static checkCacheDir ()
 Check that the cache dir exists and is writeable.
 
static cleanCache ()
 Delete unused cached files.
 

Public Attributes

 $c = serialize($c)
 
const CACHE_VERSION = 1
 

Static Public Attributes

static string false $cacheDir = false
 directory used for storing data
 
static bool string $forceRefresh = false
 force a refresh : 'once' for refreshing the first hit on a cache only, true to never use the cache in this hit
 
static int $gcLifetime = 604800
 specifies the number of seconds after which data cached will be seen as 'garbage' and potentially cleaned up
 
static string $prefix = 'scssphp_'
 prefix for the storing data
 

Static Protected Attributes

static array< string, $refreshed=[];public function __construct( $options) { if(isset( $options[ 'cacheDir'])) { self::$cacheDir=$options[ 'cacheDir'];} if(empty(self::$cacheDir)) { throw new Exception( 'cacheDir not set');} if(isset( $options[ 'prefix'])) { self::$prefix=$options[ 'prefix'];} if(empty(self::$prefix)) { throw new Exception( 'prefix not set');} if(isset( $options[ 'forceRefresh'])) { self::$forceRefresh=$options[ 'forceRefresh'];} self::checkCacheDir();} public function getCache( $operation, $what, $options=[], $lastModified=null) { $fileCache=self::$cacheDir . self::cacheName( $operation, $what, $options);if(((self::$forceRefresh===false)||(self::$forceRefresh==='once' &&isset(self::$refreshed[ $fileCache]))) &&file_exists( $fileCache)) { $cacheTime=filemtime( $fileCache);if((\is_null( $lastModified)||$cacheTime > $lastModified) &&$cacheTime+self::$gcLifetime > time()) { $c=file_get_contents( $fileCache);$c=unserialize( $c);if(\is_array( $c) &&isset( $c[ 'value'])) { return $c[ 'value'];} } } return null;} public function setCache( $operation, $what, $value, $options=[]) { $fileCache=self::$cacheDir . self::cacheName( $operation, $what, $options);$c=[ 'value'=> $value
 array of already refreshed cache if $forceRefresh==='once'
 

Detailed Description

The scss cache manager.

In short:

allow to put in cache/get from cache a generic result from a known operation on a generic dataset, taking in account options that affects the result

The cache manager is agnostic about data format and only the operation is expected to be described by string SCSS cache

Author
Cedric Morin cedri.nosp@m.c@yt.nosp@m.erium.nosp@m..com

Member Function Documentation

◆ checkCacheDir()

static ScssPhp\ScssPhp\Cache::checkCacheDir ( )
static

Check that the cache dir exists and is writeable.

Return values
void
Exceptions
Exception

◆ cleanCache()

static ScssPhp\ScssPhp\Cache::cleanCache ( )
static

Delete unused cached files.

Return values
void

Member Data Documentation

◆ $value

array<string, $refreshed = []; public function __construct($options) { if (isset($options['cacheDir'])) { self::$cacheDir = $options['cacheDir']; } if (empty(self::$cacheDir)) { throw new Exception('cacheDir not set'); } if (isset($options['prefix'])) { self::$prefix = $options['prefix']; } if (empty(self::$prefix)) { throw new Exception('prefix not set'); } if (isset($options['forceRefresh'])) { self::$forceRefresh = $options['forceRefresh']; } self::checkCacheDir(); } public function getCache($operation, $what, $options = [], $lastModified = null) { $fileCache = self::$cacheDir . self::cacheName($operation, $what, $options); if ( ((self::$forceRefresh === false) || (self::$forceRefresh === 'once' && isset(self::$refreshed[$fileCache]))) && file_exists($fileCache) ) { $cacheTime = filemtime($fileCache); if ( (\is_null($lastModified) || $cacheTime > $lastModified) && $cacheTime + self::$gcLifetime > time() ) { $c = file_get_contents($fileCache); $c = unserialize($c); if (\is_array($c) && isset($c['value'])) { return $c['value']; } } } return null; } public function setCache($operation, $what, $value, $options = []) { $fileCache = self::$cacheDir . self::cacheName($operation, $what, $options); $c = ['value' => ScssPhp\ScssPhp\Cache::$value
staticprotected

array of already refreshed cache if $forceRefresh==='once'

bool>


The documentation for this class was generated from the following file: