Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- define('DS', DIRECTORY_SEPARATOR);
- class Caches
- {
- function save($data, $namespace, $id)
- {
- $path = $this->get_namespace_path($namespace) . $this->get_id_dir($id);
- if (!file_exists($path))
- {
- mkdir($path, 0775, true);
- }
- file_put_contents($path . md5($id), $data);
- }
- function load($namespace, $id, $lifetime = 0)
- {
- $filename = $this->get_namespace_path($namespace) . $this->get_id_path($id);
- if (!file_exists($filename))
- return false;
- if (($lifetime != 0) && ((@filemtime($filename) + $lifetime) < time()))
- {
- $this->remove($namespace, $id);
- return false;
- }
- $data = file_get_contents($filename);
- return $data;
- }
- function remove($namespace, $id)
- {
- $filename = $this->get_namespace_path($namespace) . $this->get_id_path($id);
- if (file_exists($filename))
- unlink($filename);
- }
- function clean($namespace)
- {
- $filename = $this->get_namespace_path($namespace);
- if (file_exists($filename))
- unlink($filename);
- }
- private function get_id_path($id)
- {
- return $this->get_id_dir($id) . md5($id);
- }
- private function get_id_dir($id)
- {
- $hash = md5($id);
- return $hash[0] . DS . $hash[1] . DS;
- }
- private function get_namespace_path($namespace)
- {
- return ZENGINE_HOMEDIR . DS . 'zcontent' . DS . 'cache' . DS . $namespace . DS;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement