Webocreation

Monday, April 18, 2011

Opencart Cache library function




Opencart Cache library function:
Calling of the cache function from the controller or view or model
$this->cache->get($key);
This is useful to get the caches that are enabled.
The get function in the library is defined as follows:
public function get($key) {
$files = glob(DIR_CACHE . 'cache.' . $key . '.*');
if ($files) {
foreach ($files as $file) {
$handle = fopen($file, 'r');
$cache = fread($handle, filesize($file));
fclose($handle);
return unserialize($cache);
}
}
}
$this->cache->set($key, $value):
This is useful to enable the cache.
The function set is defined as below:
public function set($key, $value) {
$this->delete($key);
$file = DIR_CACHE . 'cache.' . $key . '.' . (time() + $this->expire);
$handle = fopen($file, 'w');
fwrite($handle, serialize($value));
fclose($handle);
}

$this->cache->delete($key):
This is useful to delete the cache by which we can enable the next cache by setting.
The function delete defined as follows:
public function delete($key) {
$files = glob(DIR_CACHE . 'cache.' . $key . '.*');
if ($files) {
foreach ($files as $file) {
if (file_exists($file)) {
unlink($file);
clearstatcache();
}
}
}
}

opencart function collections, funtion collection of opencart, opencart by example, learn opencart by function and example

No comments:

Post a Comment