Cache manager class
package |
Default |
---|
__construct(string $rootPath, string $zone)
This cache system is divided into zones, which are different folders inside the cache root folder. Each zone is independent, and can be named and used for whatever purpose we want. Inside each of the zones, we can store cache "sections" which are another independent cache areas which can be also used and named for anything we want. Each section contains all the cached data that we generate.
All the data is stored on plain file system, so take it into consideration when fast response times are cryitcal.
The expiration of the cache data is managed entirely by this class, so no cron or scheduled tasks should be required to clear outdated cache items.
Throws |
|
---|
string
The full absolute filesystem path to the root of the folder where all the cache data files will be stored
string
To allow different types of cache data to be stored without colliding, the cache root folder is divided into several zones. We can define here the name for a zone we want to store our cached data, and it will be used. If the zone does not exist, it will be automatically created.
clearId(string $section, string $id) : boolean
Throws |
|
---|
string
The name for a cache section (under the current zone) which id data will be deleted
string
The identifier we previously used to store the data
boolean
True on success
clearSection(string $section) : boolean
NOTE: All cached data will be deleted even if the section is not expired yet!
Throws |
|
---|
string
The name for a cache section (under the current zone) that will be deleted
boolean
True on success
clearZone() : boolean
NOTE: All cached data will be deleted even if the zone is not expired yet!
boolean
True on success
get(string $section, string $id) : string|null
string
The name for a cache section (under the current zone) where the data is stored
string
The identifier we previously used to store the data we want to retrieve
string|null
The requested data or null if data, id or section were not found
getPath(string $section, string $id) : string|null
Normally useful when the cached data is so big that should be streamed, or when we need to perform some kind of extra file operations with it.
string
The name for a cache section (under the current zone) where the data is stored
string
The identifier we previously used to store the data
string|null
The requested path or null if id or section were not found
getZoneName() : string
string
isSectionExpired( $section) : boolean
see | \org\turbodepot\src\main\php\managers\CacheManager::setSectionTimeToLive |
---|---|
Throws |
|
boolean
True if the section expiration time has been exceeded (and data is no longer available). False otherwise
isZoneExpired() : boolean
see | \org\turbodepot\src\main\php\managers\CacheManager::__construct |
---|---|
Throws |
|
boolean
True if the zone expiration time has been exceeded (and data is no longer available). False otherwise
save(string $section, string $id, string $data) : string
Throws |
|
---|
string
The name for a cache section (under the current zone) where we want to store the data.
string
A unique identifier that we want to use for the stored data. This will be required to obtain it later
string
The data we want to store.
string
The same data
setSectionTimeToLive( $section, string $timeToLive) : void
string
Defines the number of seconds after which the whole section cached data will be deleted. (1 hour = 3600 seconds, 1 day = 86400 seconds, 1 month = 2592000, 1 year = 31536000). Set it to 0 for an infinite timeout.
setZoneTimeToLive(string $timeToLive) : void
string
Defines the number of seconds after which the whole zone cache data will be deleted. (1 hour = 3600 seconds, 1 day = 86400 seconds, 1 month = 2592000, 1 year = 31536000). Set it to 0 for an infinite timeout.