Fuel Cache Class
This class is used for managing the different kinds of cached files used with FUEL including pages, compiled templates and asset files.
This class extends the Fuel_base_library class.
Properties Reference
Property | Default Value | Description |
---|---|---|
public | ||
ignore | #^(\..+)|(index\.html)# | Regular expression of files to exclude from clearing like .gitignore and .htaccess |
cache_path | /var/www/vhosts/getfuelcms.com/subdomains/docs/httpdocs/fuel/application/cache/ | The cache path. If no path is provided it will use the cache path value found in the main CI config file. |
protected | ||
_cache | N/A | |
_types | N/A |
Function Reference [+]
$this->fuel->cache->initialize([$params=array()])
Initialize the object and set object parameters. Accepts an associative array as input, containing object preferences.
Returns
void
Parameters
(array) $params Array of initalization parameters (optional)
$this->fuel->cache->set_cache_path('$path')
Sets the cache path.
Returns
void
Parameters
(string) $path The path to the cache folder
$this->fuel->cache->set_compiled_path('$path')
Sets the compiled templates path.
Returns
void
Parameters
(string) $path The path to the compiled templates folder
$this->fuel->cache->create_id(['$location'=NULL], ['$lang'=NULL])
Creates a cache ID based on the page location. If no $location value is provided, then the ID will be based on the current URI segments.
Returns
string
Parameters
(string) $location Location used in creating the ID (optional) (string) $lang Language of page (optional)
Example
$cache_id = $this->fuel->cache->create_id(); // create a cache id... this will be based on the current URI location if no parameters are passed
$this->fuel->cache->save('$cache_id', '$data', ['$group'=NULL], ['$ttl'=NULL])
Saves an item to the cache.
Returns
void
Parameters
(string) $cache_id Cache ID (string) $data Cache group ID (mixed) $group Data to save to the cache (optional) (int) $ttl Time to live in seconds for cache (optional)
Example
$cache_id = $this->fuel->cache->create_id(); $data = 'These are not the droids you are looking for.'; $file = $this->fuel->cache->save($cache_id, $data, NULL, 3600); // sets the cached item with a TTL of one hour
$this->fuel->cache->get('$cache_id', ['$cache_group'=NULL], ['$skip_checking'=FALSE])
Get and return an item from the cache.
Returns
string The contents of the cached file or NULL if it doesn't exist
Parameters
(string) $cache_id Cache ID (string) $cache_group Cache group ID (optional) (boolean) $skip_checking Skip checking if it is in the cache or not (optional)
Example
$cache_id = $this->fuel->cache->create_id(); $file = $this->fuel->cache->get($cache_id, 'pages', FALSE);
$this->fuel->cache->is_cached('$cache_id', ['$group'=NULL])
Checks if the file is cached based on the cache_id passed.
Returns
boolean
Parameters
(string) $cache_id Cache ID (string) $group Cache group ID (optional)
Example
$cache_id = $this->fuel->cache->create_id(); if ($this->fuel->cache->is_cached($cache_id)){ echo 'cached'; } else { echo 'not cached'; }
$this->fuel->cache->clear(['$what'=NULL])
Clears the various types of caches. Value passed can be either a string or an array. If a string, the value must be "compiled", "pages" or "assets". If an array, the array must contain one or more of the values (e.g. array("compiled", "pages", "assets")) If no parameters are passed, then all caches are cleared.
Returns
void
Parameters
(mixed) $what Value can be either a string of one value or an array of multiple values. Valid values are compiled, pages and assets. (optional)
Example
$this->fuel->cache->clear(array('compiled', 'pages')); // as an array $this->fuel->cache->clear('assets'); // as string
$this->fuel->cache->clear_compiled()
Clears the compiled templating files.
Returns
void
Example
$this->fuel->cache->clear(array('compiled', 'pages')); // as an array $this->fuel->cache->clear('assets'); // as string
$this->fuel->cache->clear_pages()
Clears the pages cache.
Returns
void
Example
$this->fuel->cache->clear_pages();
$this->fuel->cache->clear_page('$location')
Clear a single page from the cache.
Returns
void
Parameters
(string) $location Page location
Example
$this->fuel->cache->clear_page('about/history');
$this->fuel->cache->clear_assets()
Clears the assets cache. Will look in module asset folders if the fuel/{module}/assets/cache/ directory exist for that module.
Returns
void
Example
$this->fuel->cache->clear_assets();
$this->fuel->cache->clear_file('$cache_id')
Clears a single cache file.
Returns
void
Parameters
(string) $cache_id Cache ID
Example
$cache_id = $this->fuel->cache->create_id(); $this->fuel->cache->clear_file($cache_id);
$this->fuel->cache->clear_group('$group')
Clears a group of cached files.
Returns
void
Parameters
(string) $group Cache group ID
Example
$group = 'pages'; $this->fuel->cache->clear_group($group);
$this->fuel->cache->clear_module('$module')
Clears the cache folder for a particular module.
Returns
void
Parameters
(string) $module Module name
Example
$module = 'my_module'; $this->fuel->cache->clear_module($module);
$this->fuel->cache->clear_all_modules()
Clears all the allowed modules cache folders.
Returns
void
Example
$this->fuel->cache->clear_all_modules();
$this->fuel->cache->clear_all()
Clears all cache types. Will remove page, compiled, and cached asset files.
Returns
void
Example
$this->fuel->cache->clear_all();