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

A simple filesystem cache. More...

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

Public Member Functions

 __construct ($dir)
 
 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

 $dir
 

Detailed Description

A simple filesystem cache.

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 FilesystemCache.php.

Constructor & Destructor Documentation

◆ __construct()

Assetic\Cache\FilesystemCache::__construct (   $dir)

Definition at line 23 of file FilesystemCache.php.

References Assetic\Cache\FilesystemCache\$dir.

24  {
25  $this->dir = $dir;
26  }

Member Function Documentation

◆ get()

Assetic\Cache\FilesystemCache::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 33 of file FilesystemCache.php.

References $path.

34  {
35  $path = $this->dir.'/'.$key;
36 
37  if (!file_exists($path)) {
38  throw new \RuntimeException('There is no cached value for '.$key);
39  }
40 
41  return file_get_contents($path);
42  }
$path
Definition: aliased.php:25

◆ has()

Assetic\Cache\FilesystemCache::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 28 of file FilesystemCache.php.

29  {
30  return file_exists($this->dir.'/'.$key);
31  }

◆ remove()

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

Removes a value from the cache.

Parameters
string$keyA unique key

Implements Assetic\Cache\CacheInterface.

Definition at line 57 of file FilesystemCache.php.

References $path.

58  {
59  $path = $this->dir.'/'.$key;
60 
61  if (file_exists($path) && false === @unlink($path)) {
62  throw new \RuntimeException('Unable to remove file '.$path);
63  }
64  }
$path
Definition: aliased.php:25

◆ set()

Assetic\Cache\FilesystemCache::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 44 of file FilesystemCache.php.

References $path.

45  {
46  if (!is_dir($this->dir) && false === @mkdir($this->dir, 0777, true)) {
47  throw new \RuntimeException('Unable to create directory '.$this->dir);
48  }
49 
50  $path = $this->dir.'/'.$key;
51 
52  if (false === @file_put_contents($path, $value)) {
53  throw new \RuntimeException('Unable to write file '.$path);
54  }
55  }
$path
Definition: aliased.php:25

Field Documentation

◆ $dir

Assetic\Cache\FilesystemCache::$dir
private

Definition at line 21 of file FilesystemCache.php.

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


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