Hoa central
Public Member Functions | List of all members
Hoa\Cache\Backend\File Class Reference
Inheritance diagram for Hoa\Cache\Backend\File:

Public Member Functions

 store ($data)
 
 load ()
 
 clean ($lifetime=Cache::CLEAN_EXPIRED)
 
 remove ()
 
- Public Member Functions inherited from Hoa\Cache\Backend\Backend
 store ($data)
 
 load ()
 
 clean ($lifetime=Cache::CLEAN_EXPIRED)
 
 remove ()
 
- Public Member Functions inherited from Hoa\Cache\Cache
 __construct (Array $parameters=[])
 
 getParameters ()
 
 ksort (Array &$array)
 

Additional Inherited Members

- Public Attributes inherited from Hoa\Cache\Cache
const CLEAN_ALL = -1
 
const CLEAN_EXPIRED = 0
 
const CLEAN_USER = 1
 
- Protected Member Functions inherited from Hoa\Cache\Cache
 makeId ($id=null)
 
 setId ($id)
 
 getId ()
 
 getIdMd5 ()
 
 removeId ()
 
- Static Protected Attributes inherited from Hoa\Cache\Cache
static $_id = []
 

Detailed Description

Class .

File backend manager.

Definition at line 50 of file File.php.

Member Function Documentation

Hoa\Cache\Backend\File::clean (   $lifetime = Cache::CLEAN_EXPIRED)

Clean expired cache files. Note : ::CLEAN_USER is not supported, it's reserved for APC backend.

Parameters
int$lifetimeLifetime of caches.
Returns
void
Exceptions

Definition at line 128 of file File.php.

129  {
130  switch ($lifetime) {
131  case Cache::CLEAN_ALL:
132  break;
133 
135  $lifetime = $this->_parameters->getParameter('lifetime');
136 
137  break;
138 
139  case Cache::CLEAN_USER:
140  throw new Cache\Exception(
141  '\Hoa\Cache::CLEAN_USER constant is not supported by %s.' .
142  2,
143  __CLASS__
144  );
145 
146  default:
147  $lifetime = $lifetime;
148  }
149 
150  $this->setId($this->getIdMd5());
151 
152  try {
153  $cacheDirectory = $this->_parameters->getFormattedParameter(
154  'file.cache.directory'
155  );
156  $finder = new HoaFile\Finder();
157  $finder
158  ->in($cacheDirectory)
159  ->files()
160  ->modified('since ' . $lifetime . ' seconds');
161 
162  foreach ($finder as $file) {
163  $file->open()->delete();
164  $file->close();
165  }
166  } catch (HoaFile\Exception\FileDoesNotExist $e) {
167  }
168 
169  return;
170  }
const CLEAN_EXPIRED
Definition: Cache.php:62
const CLEAN_ALL
Definition: Cache.php:55
const CLEAN_USER
Definition: Cache.php:69

Here is the call graph for this function:

Here is the caller graph for this function:

Hoa\Cache\Backend\File::load ( )

Load a cache file.

Returns
mixed

Definition at line 93 of file File.php.

94  {
95  $this->clean();
96  $this->setId($this->getIdMd5());
97 
98  $filename =
99  $this->_parameters->getFormattedParameter('file.cache.directory') .
100  $this->_parameters->getFormattedParameter('file.cache.file');
101 
102  if (false === file_exists($filename)) {
103  return false;
104  }
105 
106  $content = file_get_contents($filename);
107 
108  if (true === $this->_parameters->getParameter('file.compress.active')) {
109  $content = gzuncompress($content);
110  }
111 
112  if (true === $this->_parameters->getParameter('serialize_content')) {
113  $content = unserialize($content);
114  }
115 
116  return $content;
117  }
clean($lifetime=Cache::CLEAN_EXPIRED)
Definition: File.php:128
$content
Definition: Hoa.php:119

Here is the call graph for this function:

Hoa\Cache\Backend\File::remove ( )

Remove a cache file.

Returns
void

Definition at line 177 of file File.php.

178  {
179  $this->setId($this->getIdMd5());
180 
181  $filename =
182  $this->_parameters->getFormattedParameter('file.cache.directory') .
183  $this->_parameters->getFormattedParameter('file.cache.file');
184 
185  $file = new HoaFile\Read($filename);
186  $file->delete();
187  $file->close();
188 
189  return;
190  }

Here is the call graph for this function:

Hoa\Cache\Backend\File::store (   $data)

Save cache content into a file.

Parameters
mixed$dataData to store.
Returns
void

Definition at line 58 of file File.php.

59  {
60  $this->clean();
61 
62  if (true === $this->_parameters->getParameter('serialize_content')) {
63  $data = serialize($data);
64  }
65 
66  if (true === $this->_parameters->getParameter('file.compress.active')) {
67  $data = gzcompress(
68  $data,
69  $this->_parameters->getParameter('file.compress.level')
70  );
71  }
72 
73  $this->setId($this->getIdMd5());
74  $directory =
75  $this->_parameters->getFormattedParameter('file.cache.directory');
76 
77  @mkdir($directory, 0755, true);
78 
79  file_put_contents(
80  $directory .
81  $this->_parameters->getFormattedParameter('file.cache.file'),
82  $data
83  );
84 
85  return;
86  }
clean($lifetime=Cache::CLEAN_EXPIRED)
Definition: File.php:128

Here is the call graph for this function:


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