ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
Assetic\Cache\ExpiringCache Class Reference

Adds expiration to a cache backend. More...

+ Inheritance diagram for Assetic\Cache\ExpiringCache:
+ Collaboration diagram for Assetic\Cache\ExpiringCache:

Public Member Functions

 __construct (CacheInterface $cache, $lifetime)
 
 has ($key)
 Checks if the cache has a value for a key. More...
 
 get ($key)
 Returns the value for a key. More...
 
 set ($key, $value)
 Sets a value in the cache. More...
 
 remove ($key)
 Removes a value from the cache. More...
 

Private Attributes

 $cache
 
 $lifetime
 

Detailed Description

Adds expiration to a cache backend.

Author
Kris Wallsmith kris..nosp@m.wall.nosp@m.smith.nosp@m.@gma.nosp@m.il.co.nosp@m.m

Definition at line 19 of file ExpiringCache.php.

Constructor & Destructor Documentation

◆ __construct()

Assetic\Cache\ExpiringCache::__construct ( CacheInterface  $cache,
  $lifetime 
)

Definition at line 24 of file ExpiringCache.php.

References Assetic\Cache\ExpiringCache\$cache, and Assetic\Cache\ExpiringCache\$lifetime.

25  {
26  $this->cache = $cache;
27  $this->lifetime = $lifetime;
28  }

Member Function Documentation

◆ get()

Assetic\Cache\ExpiringCache::get (   $key)

Returns the value for a key.

Parameters
string$keyA unique key
Returns
string|null The value in the cache

Implements Assetic\Cache\CacheInterface.

Definition at line 44 of file ExpiringCache.php.

45  {
46  return $this->cache->get($key);
47  }

◆ has()

Assetic\Cache\ExpiringCache::has (   $key)

Checks if the cache has a value for a key.

Parameters
string$keyA unique key
Returns
Boolean Whether the cache has a value for this key

Implements Assetic\Cache\CacheInterface.

Definition at line 30 of file ExpiringCache.php.

References time.

31  {
32  if ($this->cache->has($key)) {
33  if (time() < $this->cache->get($key.'.expires')) {
34  return true;
35  }
36 
37  $this->cache->remove($key.'.expires');
38  $this->cache->remove($key);
39  }
40 
41  return false;
42  }
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.

◆ remove()

Assetic\Cache\ExpiringCache::remove (   $key)

Removes a value from the cache.

Parameters
string$keyA unique key

Implements Assetic\Cache\CacheInterface.

Definition at line 55 of file ExpiringCache.php.

56  {
57  $this->cache->remove($key.'.expires');
58  $this->cache->remove($key);
59  }

◆ set()

Assetic\Cache\ExpiringCache::set (   $key,
  $value 
)

Sets a value in the cache.

Parameters
string$keyA unique key
string$valueThe value to cache

Implements Assetic\Cache\CacheInterface.

Definition at line 49 of file ExpiringCache.php.

References time.

50  {
51  $this->cache->set($key.'.expires', time() + $this->lifetime);
52  $this->cache->set($key, $value);
53  }
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.

Field Documentation

◆ $cache

Assetic\Cache\ExpiringCache::$cache
private

Definition at line 21 of file ExpiringCache.php.

Referenced by Assetic\Cache\ExpiringCache\__construct().

◆ $lifetime

Assetic\Cache\ExpiringCache::$lifetime
private

Definition at line 22 of file ExpiringCache.php.

Referenced by Assetic\Cache\ExpiringCache\__construct().


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