PageRenderTime 193ms CodeModel.GetById 81ms app.highlight 3ms RepoModel.GetById 108ms app.codeStats 0ms

/library/cache/drivers/php.php

http://github.com/pateketrueke/tetlphp
PHP | 53 lines | 33 code | 12 blank | 8 comment | 3 complexity | 6b88950bf80453e026d9470ff0feb707 MD5 | raw file
 1<?php
 2
 3/**
 4 * PHP based cache adapter
 5 */
 6
 7/**#@+
 8 * @ignore
 9 */
10define('CACHE_DRIVER', 'PHP');
11/**#@-*/
12
13
14cache::implement('free_all', function () {
15  foreach (dir2arr(TMP, '--cache-php*') as $cache_file) {
16    @unlink(TMP.DS.$cache_file);
17  }
18});
19
20cache::implement('fetch_item', function ($key) {
21  if (is_file($cache_file = TMP.DS.'--cache-php'.md5($key))) {
22    $test = include $cache_file;
23
24    if ( ! is_array($test)) {
25      return @unlink($path);
26    } elseif (time() < $test[0]) {
27      return $test[1];
28    }
29    @unlink($cache_file);
30  }
31  return FALSE;
32});
33
34cache::implement('store_item', function ($key, $set = array(), $ttl = 0) {
35  $cache_file = TMP.DS.'--cache-php'.md5($key);
36
37  $vars = var_export($set, TRUE);
38  $code = sprintf('<' . '?php return array(%s, %s);', time() + $ttl, $vars);
39
40  return write($cache_file, $code);
41});
42
43cache::implement('delete_item', function ($key) {
44  if (is_file($cache_file = TMP.DS.'--cache-php'.md5($key))) {
45    return @unlink($cache_file);
46  }
47});
48
49cache::implement('check_item', function ($key) {
50  return ! is_false(cache::fetch_item($key));
51});
52
53/* EOF: ./library/cache/drivers/php.php */