Class FileEngine
File Storage engine for cache. Filestorage is the slowest cache storage to read and write. However, it is good for servers that don't have other storage engine available, or have content which is not performance sensitive.
You can configure a FileEngine cache, using Cache::config()
- CacheEngine
- FileEngine
Copyright: Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
License: MIT License
Location: Cake/Cache/Engine/FileEngine.php
Properties summary
-
$_File
protected -
$_init
protectedTrue unless FileEngine::__active(); failsboolean
-
$settings
publicSettingsarray
Inherited Properties
Method Summary
- _active() protectedDetermine is cache directory is writable
- _clearDirectory() protectedUsed to clear a directory of matching files.
- _setKey() protected
Sets the current cache key this class is managing, and creates a writable SplFileObject for the cache file the key is referring to.
- add() public
Write data for key into cache if it doesn't exist already. If it already exists, it fails and returns false.
- clear() publicDelete all values from the cache
- clearGroup() publicRecursively deletes all files under any directory named as $group
- decrement() publicNot implemented
- delete() publicDelete a key from the cache
- gc() publicGarbage collection. Permanently remove all expired and deleted data
- increment() publicNot implemented
- init() publicInitialize the Cache Engine
- key() publicGenerates a safe key for use with cache engine storage engines.
- read() publicRead a key from the cache
- write() publicWrite data for key into cache
Method Detail
_clearDirectory()source protected
_clearDirectory( string $path , integer $now , integer $threshold )
Used to clear a directory of matching files.
Parameters
- string
$path
- The path to search.
- integer
$now
- The current timestamp
- integer
$threshold
- Any file not modified after this value will be deleted.
_setKey()source protected
_setKey( string $key , boolean $createKey false )
Sets the current cache key this class is managing, and creates a writable SplFileObject for the cache file the key is referring to.
Parameters
- string
$key
- The key
- boolean
$createKey
optional false - Whether the key should be created if it doesn't exists, or not
Returns
booleantrue if the cache key could be set, false otherwise
add()source public
add( string $key , mixed $value , integer $duration )
Write data for key into cache if it doesn't exist already. If it already exists, it fails and returns false.
Parameters
- string
$key
- Identifier for the data.
- mixed
$value
- Data to be cached.
- integer
$duration
- How long to cache the data, in seconds.
Returns
booleanTrue if the data was successfully cached, false on failure.
Overrides
CacheEngine::add()
clear()source public
clear( boolean $check )
Delete all values from the cache
Parameters
- boolean
$check
- Optional - only delete expired cache items
Returns
booleanTrue if the cache was successfully cleared, false otherwise
clearGroup()source public
clearGroup( string $group )
Recursively deletes all files under any directory named as $group
Parameters
- string
$group
- The group to clear.
Returns
booleansuccess
Overrides
CacheEngine::clearGroup()
decrement()source public
decrement( string $key , integer $offset 1 )
Not implemented
Parameters
- string
$key
- The key to decrement
- integer
$offset
optional 1 - The number to offset
Throws
CacheException
delete()source public
delete( string $key )
Delete a key from the cache
Parameters
- string
$key
- Identifier for the data
Returns
booleanTrue if the value was successfully deleted, false if it didn't exist or couldn't be removed
gc()source public
gc( integer $expires null )
Garbage collection. Permanently remove all expired and deleted data
Parameters
- integer
$expires
optional null - [optional] An expires timestamp, invalidating all data before.
Returns
booleanTrue if garbage collection was successful, false on failure
Overrides
CacheEngine::gc()
increment()source public
increment( string $key , integer $offset 1 )
Not implemented
Parameters
- string
$key
- The key to decrement
- integer
$offset
optional 1 - The number to offset
Throws
CacheException
init()source public
init( array $settings array() )
Initialize the Cache Engine
Called automatically by the cache frontend To reinitialize the settings call Cache::engine('EngineName', [optional] settings = array());
Parameters
- array
$settings
optional array() - array of setting for the engine
Returns
booleanTrue if the engine has been successfully initialized, false if not
Overrides
CacheEngine::init()
key()source public
key( string $key )
Generates a safe key for use with cache engine storage engines.
Parameters
- string
$key
- the key passed over
Returns
mixedstring $key or false
Overrides
CacheEngine::key()
read()source public
read( string $key )
Read a key from the cache
Parameters
- string
$key
- Identifier for the data
Returns
mixedThe cached data, or false if the data doesn't exist, has expired, or if there was an error fetching it
write()source public
write( string $key , mixed $data , integer $duration )
Write data for key into cache
Parameters
- string
$key
- Identifier for the data
- mixed
$data
- Data to be cached
- integer
$duration
- How long to cache the data, in seconds
Returns
booleanTrue if the data was successfully cached, false on failure
Methods inherited from CacheEngine
groups()source public
groups( )
Does whatever initialization for each group is required and returns the group value
for each of them, this is the token representing each group in the cache key
Returns
arrayProperties detail
$settingssource
public array
Settings
- path = absolute path to cache directory, default => CACHE
- prefix = string prefix for filename, default => cake_
- lock = enable file locking on write, default => true
- serialize = serialize the data, default => true
See
CacheEngine::__defaultsarray()
© 2005–2017 The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/2.10/class-FileEngine.html