|
| _getMetadatas ($id) |
|
| _setMetadatas ($id, $metadatas, $save=true) |
|
| _delMetadatas ($id) |
|
| _cleanMetadatas () |
|
| _loadMetadatas ($id) |
|
| _saveMetadatas ($id, $metadatas) |
|
| _metadatasFile ($id) |
|
| _isMetadatasFile ($fileName) |
|
| _remove ($file) |
|
| _clean ($dir, $mode=Zend_Cache::CLEANING_MODE_ALL, $tags=array()) |
|
| _get ($dir, $mode, $tags=array()) |
|
| _expireTime ($lifetime) |
|
| _hash ($data, $controlType) |
|
| _idToFileName ($id) |
|
| _file ($id) |
|
| _path ($id, $parts=false) |
|
| _recursiveMkdirAndChmod ($id) |
|
| _test ($id, $doNotTestCacheValidity) |
|
| _fileGetContents ($file) |
|
| _filePutContents ($file, $string) |
|
| _fileNameToId ($fileName) |
|
| _isGoodTmpDir ($dir) |
|
| _loggerSanity () |
|
| _log ($message, $priority=4) |
|
Definition at line 40 of file File.php.
◆ __construct()
__construct |
( |
array |
$options = array() | ) |
|
Constructor
- Parameters
-
array | $options | associative array of options |
- Exceptions
-
Definition at line 124 of file File.php.
127 if ($this->_options[
'cache_dir'] !==
null) {
130 $this->
setCacheDir(self::getTmpDir() . DIRECTORY_SEPARATOR,
false);
132 if (isset($this->_options[
'file_name_prefix'])) {
133 if (!preg_match(
'~^[a-zA-Z0-9_]+$~D', $this->_options[
'file_name_prefix'])) {
137 if ($this->_options[
'metadatas_array_max_size'] < 10) {
141 if (isset(
$options[
'hashed_directory_umask'])) {
143 trigger_error(
"'hashed_directory_umask' is deprecated -> please use 'hashed_directory_perm' instead", E_USER_NOTICE);
144 if (!isset(
$options[
'hashed_directory_perm'])) {
148 if (isset(
$options[
'hashed_directory_perm']) && is_string(
$options[
'hashed_directory_perm'])) {
150 $this->_options[
'hashed_directory_perm'] = octdec($this->_options[
'hashed_directory_perm']);
153 if (isset(
$options[
'cache_file_umask'])) {
155 trigger_error(
"'cache_file_umask' is deprecated -> please use 'cache_file_perm' instead", E_USER_NOTICE);
156 if (!isset(
$options[
'cache_file_perm'])) {
160 if (isset(
$options[
'cache_file_perm']) && is_string(
$options[
'cache_file_perm'])) {
162 $this->_options[
'cache_file_perm'] = octdec($this->_options[
'cache_file_perm']);
setCacheDir($value, $trailingSeparator=true)
static throwException($msg, Exception $e=null)
◆ ___expire()
PUBLIC METHOD FOR UNIT TESTING ONLY !
Force a cache record to expire
- Parameters
-
Definition at line 483 of file File.php.
487 $metadatas[
'expire'] = 1;
_setMetadatas($id, $metadatas, $save=true)
◆ _clean()
Clean some cache records (protected method used for recursive stuff)
Available modes are : Zend_Cache::CLEANING_MODE_ALL (default) => remove all cache entries ($tags is not used) Zend_Cache::CLEANING_MODE_OLD => remove too old cache entries ($tags is not used) Zend_Cache::CLEANING_MODE_MATCHING_TAG => remove cache entries matching all given tags ($tags can be an array of strings or a single string) Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG => remove cache entries not {matching one of the given tags} ($tags can be an array of strings or a single string) Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG => remove cache entries matching any given tags ($tags can be an array of strings or a single string)
- Parameters
-
string | $dir | Directory to clean |
string | $mode | Clean mode |
array | $tags | Array of tags |
- Exceptions
-
- Returns
- boolean True if no problem
Definition at line 665 of file File.php.
671 $prefix = $this->_options[
'file_name_prefix'];
672 $glob = @glob($dir .
$prefix .
'--*');
673 if ($glob ===
false) {
677 $metadataFiles = array();
678 foreach ($glob as $file) {
685 $metadataFiles[] = $file;
691 if ($metadatas === FALSE) {
692 $metadatas = array(
'expire' => 1,
'tags' => array());
699 if (
time() > $metadatas[
'expire']) {
705 foreach ($tags as $tag) {
706 if (!in_array($tag, $metadatas[
'tags'])) {
717 foreach ($tags as $tag) {
718 if (in_array($tag, $metadatas[
'tags'])) {
729 foreach ($tags as $tag) {
730 if (in_array($tag, $metadatas[
'tags'])) {
744 if ((
is_dir($file)) and ($this->_options[
'hashed_directory_level']>0)) {
755 foreach ($metadataFiles as $file) {
756 if (file_exists($file)) {
_clean($dir, $mode=Zend_Cache::CLEANING_MODE_ALL, $tags=array())
_isMetadatasFile($fileName)
const CLEANING_MODE_NOT_MATCHING_TAG
if($exist=($block->getProductCollection() && $block->getProductCollection() ->getSize())) $mode
static throwException($msg, Exception $e=null)
const CLEANING_MODE_MATCHING_ANY_TAG
const CLEANING_MODE_MATCHING_TAG
◆ _cleanMetadatas()
Clear the metadatas array
- Returns
- void
Definition at line 556 of file File.php.
558 $this->_metadatasArray = array();
◆ _delMetadatas()
Drop a metadata record
- Parameters
-
- Returns
- boolean True if no problem
Definition at line 542 of file File.php.
544 if (isset($this->_metadatasArray[
$id])) {
545 unset($this->_metadatasArray[
$id]);
◆ _expireTime()
Compute & return the expire time
- Parameters
-
- Returns
- int expire time (unix timestamp)
Definition at line 854 of file File.php.
856 if ($lifetime ===
null) {
859 return time() + $lifetime;
◆ _file()
Make and return a file name (with path)
- Parameters
-
- Returns
- string File name (with path)
Definition at line 905 of file File.php.
◆ _fileGetContents()
_fileGetContents |
( |
|
$file | ) |
|
|
protected |
Return the file content of the given file
- Parameters
-
string | $file | File complete path |
- Returns
- string File content (or false if problem)
Definition at line 984 of file File.php.
990 $f = @
fopen($file,
'rb');
992 if ($this->_options[
'file_locking']) @flock($f, LOCK_SH);
993 $result = stream_get_contents($f);
994 if ($this->_options[
'file_locking']) @flock($f, LOCK_UN);
◆ _fileNameToId()
_fileNameToId |
( |
|
$fileName | ) |
|
|
protected |
Transform a file name into cache id and return it
- Parameters
-
- Returns
- string Cache id
Definition at line 1031 of file File.php.
1033 $prefix = $this->_options[
'file_name_prefix'];
◆ _filePutContents()
_filePutContents |
( |
|
$file, |
|
|
|
$string |
|
) |
| |
|
protected |
Put the given string into the given file
- Parameters
-
string | $file | File complete path |
string | $string | String to put in file |
- Returns
- boolean true if no problem
Definition at line 1007 of file File.php.
1010 $f = @
fopen($file,
'ab+');
1012 if ($this->_options[
'file_locking']) @flock($f, LOCK_EX);
1015 $tmp = @
fwrite($f, $string);
1016 if (!($tmp === FALSE)) {
1021 @
chmod($file, $this->_options[
'cache_file_perm']);
◆ _get()
_get |
( |
|
$dir, |
|
|
|
$mode, |
|
|
|
$tags = array() |
|
) |
| |
|
protected |
Definition at line 764 of file File.php.
770 $prefix = $this->_options[
'file_name_prefix'];
771 $glob = @glob($dir .
$prefix .
'--*');
772 if ($glob ===
false) {
776 foreach ($glob as $file) {
781 if ($metadatas === FALSE) {
784 if (
time() > $metadatas[
'expire']) {
796 foreach ($tags as $tag) {
797 if (!in_array($tag, $metadatas[
'tags'])) {
808 foreach ($tags as $tag) {
809 if (in_array($tag, $metadatas[
'tags'])) {
820 foreach ($tags as $tag) {
821 if (in_array($tag, $metadatas[
'tags'])) {
835 if ((
is_dir($file)) and ($this->_options[
'hashed_directory_level']>0)) {
837 $recursiveRs = $this->
_get($file . DIRECTORY_SEPARATOR,
$mode, $tags);
838 if ($recursiveRs ===
false) {
839 $this->
_log(
'Zend_Cache_Backend_File::_get() / recursive call : can\'t list entries of "'.$file.
'"');
_get($dir, $mode, $tags=array())
_log($message, $priority=4)
if($exist=($block->getProductCollection() && $block->getProductCollection() ->getSize())) $mode
static throwException($msg, Exception $e=null)
◆ _getMetadatas()
Get a metadatas record
- Parameters
-
- Returns
- array|false Associative array of metadatas
Definition at line 498 of file File.php.
500 if (isset($this->_metadatasArray[
$id])) {
501 return $this->_metadatasArray[
$id];
_setMetadatas($id, $metadatas, $save=true)
◆ _hash()
_hash |
( |
|
$data, |
|
|
|
$controlType |
|
) |
| |
|
protected |
Make a control key with the string containing datas
- Parameters
-
string | $data | Data |
string | $controlType | Type of control 'md5', 'crc32' or 'strlen' |
- Exceptions
-
- Returns
- string Control key
Definition at line 870 of file File.php.
872 switch ($controlType) {
878 return strlen(
$data);
880 return hash(
'adler32',
$data);
static throwException($msg, Exception $e=null)
◆ _idToFileName()
Transform a cache id into a file name and return it
- Parameters
-
- Returns
- string File name
Definition at line 892 of file File.php.
894 $prefix = $this->_options[
'file_name_prefix'];
◆ _isMetadatasFile()
_isMetadatasFile |
( |
|
$fileName | ) |
|
|
protected |
Check if the given filename is a metadatas one
- Parameters
-
- Returns
- boolean True if it's a metadatas one
Definition at line 614 of file File.php.
617 if (substr(
$id, 0, 21) ==
'internal-metadatas---') {
◆ _loadMetadatas()
Load metadatas from disk
- Parameters
-
- Returns
- array|false Metadatas associative array
Definition at line 567 of file File.php.
◆ _metadatasFile()
Make and return a file name (with path) for metadatas
- Parameters
-
- Returns
- string Metadatas file name (with path)
Definition at line 601 of file File.php.
◆ _path()
_path |
( |
|
$id, |
|
|
|
$parts = false |
|
) |
| |
|
protected |
Return the complete directory path of a filename (including hashedDirectoryStructure)
- Parameters
-
string | $id | Cache id |
boolean | $parts | if true, returns array of directory parts instead of single string |
- Returns
- string Complete directory path
Definition at line 919 of file File.php.
921 $partsArray = array();
922 $root = $this->_options[
'cache_dir'];
923 $prefix = $this->_options[
'file_name_prefix'];
924 if ($this->_options[
'hashed_directory_level']>0) {
925 $hash = hash(
'adler32',
$id);
926 for (
$i=0 ;
$i < $this->_options[
'hashed_directory_level'] ;
$i++) {
927 $root = $root .
$prefix .
'--' . substr($hash, 0,
$i + 1) . DIRECTORY_SEPARATOR;
928 $partsArray[] = $root;
◆ _recursiveMkdirAndChmod()
_recursiveMkdirAndChmod |
( |
|
$id | ) |
|
|
protected |
Make the directory strucuture for the given id
- Parameters
-
- Returns
- boolean true
Definition at line 944 of file File.php.
946 if ($this->_options[
'hashed_directory_level'] <=0) {
949 $partsArray = $this->
_path(
$id,
true);
950 foreach ($partsArray as $part) {
952 @
mkdir($part, $this->_options[
'hashed_directory_perm']);
953 @
chmod($part, $this->_options[
'hashed_directory_perm']);
mkdir($pathname, $mode=0777, $recursive=false, $context=null)
◆ _remove()
Remove a file
If we can't remove the file (because of locks or any problem), we will touch the file to invalidate it
- Parameters
-
string | $file | Complete file path |
- Returns
- boolean True if ok
Definition at line 633 of file File.php.
639 # we can't remove the file (because of locks or any problem) 640 $this->
_log(
"Zend_Cache_Backend_File::_remove() : we can't remove $file");
_log($message, $priority=4)
◆ _saveMetadatas()
_saveMetadatas |
( |
|
$id, |
|
|
|
$metadatas |
|
) |
| |
|
protected |
Save metadatas to disk
- Parameters
-
string | $id | Cache id |
array | $metadatas | Associative array |
- Returns
- boolean True if no problem
Definition at line 585 of file File.php.
_filePutContents($file, $string)
◆ _setMetadatas()
_setMetadatas |
( |
|
$id, |
|
|
|
$metadatas, |
|
|
|
$save = true |
|
) |
| |
|
protected |
Set a metadatas record
- Parameters
-
string | $id | Cache id |
array | $metadatas | Associative array of metadatas |
boolean | $save | optional pass false to disable saving to file |
- Returns
- boolean True if no problem
Definition at line 520 of file File.php.
522 if (count($this->_metadatasArray) >= $this->_options[
'metadatas_array_max_size']) {
523 $n = (int) ($this->_options[
'metadatas_array_max_size'] / 10);
524 $this->_metadatasArray = array_slice($this->_metadatasArray, $n);
532 $this->_metadatasArray[
$id] = $metadatas;
_saveMetadatas($id, $metadatas)
◆ _test()
_test |
( |
|
$id, |
|
|
|
$doNotTestCacheValidity |
|
) |
| |
|
protected |
Test if the given cache id is available (and still valid as a cache record)
- Parameters
-
string | $id | Cache id |
boolean | $doNotTestCacheValidity | If set to true, the cache validity won't be tested |
- Returns
- boolean|mixed false (a cache is not available) or "last modified" timestamp (int) of the available cache record
Definition at line 966 of file File.php.
972 if ($doNotTestCacheValidity || (
time() <= $metadatas[
'expire'])) {
973 return $metadatas[
'mtime'];
◆ clean()
◆ getCapabilities()
Return an associative array of capabilities (booleans) of the backend
The array must include these keys :
- automatic_cleaning (is automating cleaning necessary)
- tags (are tags supported)
- expired_read (is it possible to read expired cache records (for doNotTestCacheValidity option for example))
- priority does the backend deal with priority when saving
- infinite_lifetime (is infinite lifetime can work with this backend)
- get_list (is it possible to get the list of cache ids and the complete list of tags)
- Returns
- array associative of with capabilities
Implements Zend_Cache_Backend_ExtendedInterface.
Definition at line 464 of file File.php.
467 'automatic_cleaning' =>
true,
469 'expired_read' =>
true,
471 'infinite_lifetime' =>
true,
◆ getFillingPercentage()
Return the filling percentage of the backend storage
- Exceptions
-
- Returns
- int integer between 0 and 100
Implements Zend_Cache_Backend_ExtendedInterface.
Definition at line 380 of file File.php.
383 $total = disk_total_space($this->_options[
'cache_dir']);
387 if ($free >= $total) {
390 return ((
int) (100. * ($total - $free) / $total));
static throwException($msg, Exception $e=null)
◆ getIds()
Return an array of stored cache ids
- Returns
- array array of stored cache ids (string)
Implements Zend_Cache_Backend_ExtendedInterface.
Definition at line 320 of file File.php.
322 return $this->
_get($this->_options[
'cache_dir'],
'ids', array());
_get($dir, $mode, $tags=array())
◆ getIdsMatchingAnyTags()
getIdsMatchingAnyTags |
( |
|
$tags = array() | ) |
|
Return an array of stored cache ids which match any given tags
In case of multiple tags, a logical AND is made between tags
- Parameters
-
- Returns
- array array of any matching cache ids (string)
Implements Zend_Cache_Backend_ExtendedInterface.
Definition at line 369 of file File.php.
371 return $this->
_get($this->_options[
'cache_dir'],
'matchingAny', $tags);
_get($dir, $mode, $tags=array())
◆ getIdsMatchingTags()
getIdsMatchingTags |
( |
|
$tags = array() | ) |
|
Return an array of stored cache ids which match given tags
In case of multiple tags, a logical AND is made between tags
- Parameters
-
- Returns
- array array of matching cache ids (string)
Implements Zend_Cache_Backend_ExtendedInterface.
Definition at line 343 of file File.php.
345 return $this->
_get($this->_options[
'cache_dir'],
'matching', $tags);
_get($dir, $mode, $tags=array())
◆ getIdsNotMatchingTags()
getIdsNotMatchingTags |
( |
|
$tags = array() | ) |
|
Return an array of stored cache ids which don't match given tags
In case of multiple tags, a logical OR is made between tags
- Parameters
-
- Returns
- array array of not matching cache ids (string)
Implements Zend_Cache_Backend_ExtendedInterface.
Definition at line 356 of file File.php.
358 return $this->
_get($this->_options[
'cache_dir'],
'notMatching', $tags);
_get($dir, $mode, $tags=array())
◆ getMetadatas()
Return an array of metadatas for the given cache id
The array must include these keys :
- expire : the expire timestamp
- tags : a string array of tags
- mtime : timestamp of last modification time
- Parameters
-
- Returns
- array array of metadatas (false if the cache id is not found)
Implements Zend_Cache_Backend_ExtendedInterface.
Definition at line 405 of file File.php.
411 if (
time() > $metadatas[
'expire']) {
415 'expire' => $metadatas[
'expire'],
416 'tags' => $metadatas[
'tags'],
417 'mtime' => $metadatas[
'mtime']
◆ getTags()
Return an array of stored tags
- Returns
- array array of stored tags (string)
Implements Zend_Cache_Backend_ExtendedInterface.
Definition at line 330 of file File.php.
332 return $this->
_get($this->_options[
'cache_dir'],
'tags', array());
_get($dir, $mode, $tags=array())
◆ load()
load |
( |
|
$id, |
|
|
|
$doNotTestCacheValidity = false |
|
) |
| |
Test if a cache is available for the given id and (if yes) return it (false else)
- Parameters
-
string | $id | cache id |
boolean | $doNotTestCacheValidity | if set to true, the cache validity won't be tested |
- Returns
- string|false cached datas
Implements Zend_Cache_Backend_Interface.
Definition at line 196 of file File.php.
198 if (!($this->
_test(
$id, $doNotTestCacheValidity))) {
205 if ($this->_options[
'read_control']) {
206 $hashData = $this->
_hash(
$data, $this->_options[
'read_control_type']);
207 $hashControl = $metadatas[
'hash'];
208 if ($hashData != $hashControl) {
210 $this->
_log(
'Zend_Cache_Backend_File::load() / read_control : stored hash and computed hash do not match');
_log($message, $priority=4)
_test($id, $doNotTestCacheValidity)
_hash($data, $controlType)
◆ remove()
Remove a cache record
- Parameters
-
- Returns
- boolean true if no problem
Implements Zend_Cache_Backend_Interface.
Definition at line 282 of file File.php.
285 $boolRemove = $this->
_remove($file);
287 return $boolMetadata && $boolRemove;
◆ save()
save |
( |
|
$data, |
|
|
|
$id, |
|
|
|
$tags = array() , |
|
|
|
$specificLifetime = false |
|
) |
| |
Save some string datas into a cache record
Note : $data is always "string" (serialization is done by the core not by the backend)
- Parameters
-
string | $data | Datas to cache |
string | $id | Cache id |
array | $tags | Array of strings, the cache record will be tagged by each string entry |
boolean | int | $specificLifetime | If != false, set a specific lifetime for this cache record (null => infinite lifetime) |
- Returns
- boolean true if no problem
Implements Zend_Cache_Backend_Interface.
Definition at line 242 of file File.php.
247 if ($this->_options[
'hashed_directory_level'] > 0) {
256 if ($this->_options[
'read_control']) {
257 $hash = $this->
_hash(
$data, $this->_options[
'read_control_type']);
269 $this->
_log(
'Zend_Cache_Backend_File::save() / error on saving metadata');
_log($message, $priority=4)
_filePutContents($file, $string)
_recursiveMkdirAndChmod($id)
_setMetadatas($id, $metadatas, $save=true)
getLifetime($specificLifetime)
_hash($data, $controlType)
◆ setCacheDir()
setCacheDir |
( |
|
$value, |
|
|
|
$trailingSeparator = true |
|
) |
| |
Set the cache_dir (particular case of setOption() method)
- Parameters
-
string | $value | |
boolean | $trailingSeparator | If true, add a trailing separator is necessary |
- Exceptions
-
- Returns
- void
Definition at line 174 of file File.php.
182 if ($trailingSeparator) {
184 $value = rtrim(realpath(
$value),
'\\/') . DIRECTORY_SEPARATOR;
186 $this->_options[
'cache_dir'] =
$value;
static throwException($msg, Exception $e=null)
◆ test()
Test if a cache is available or not (for the given id)
- Parameters
-
- Returns
- mixed false (a cache is not available) or "last modified" timestamp (int) of the available cache record
Implements Zend_Cache_Backend_Interface.
Definition at line 224 of file File.php.
_test($id, $doNotTestCacheValidity)
◆ touch()
touch |
( |
|
$id, |
|
|
|
$extraLifetime |
|
) |
| |
Give (if possible) an extra lifetime to the given cache id
- Parameters
-
string | $id | cache id |
int | $extraLifetime | |
- Returns
- boolean true if ok
Implements Zend_Cache_Backend_ExtendedInterface.
Definition at line 428 of file File.php.
434 if (
time() > $metadatas[
'expire']) {
437 $newMetadatas = array(
438 'hash' => $metadatas[
'hash'],
440 'expire' => $metadatas[
'expire'] + $extraLifetime,
441 'tags' => $metadatas[
'tags']
_setMetadatas($id, $metadatas, $save=true)
◆ $_metadatasArray
$_metadatasArray = array() |
|
protected |
◆ $_options
Initial value:= array(
'cache_dir' => null,
'file_locking' => true,
'read_control' => true,
'read_control_type' => 'crc32',
'hashed_directory_level' => 0,
'hashed_directory_perm' => 0700,
'file_name_prefix' => 'zend_cache',
'cache_file_perm' => 0600,
'metadatas_array_max_size' => 100
)
Definition at line 98 of file File.php.
The documentation for this class was generated from the following file:
- vendor/magento/zendframework1/library/Zend/Cache/Backend/File.php