source: spip-zone/_plugins_/xcache/inc/xcache.php @ 32424

Last change on this file since 32424 was 32424, checked in by fil@…, 11 years ago

API de cache complete

File size: 995 bytes
Line 
1<?php
2
3# xcache ?
4if (function_exists('xcache_set'))
5        require_once dirname(__FILE__).'/'.'xcache.inc';
6
7//
8// Cache a function's result cache_me()
9// (c) Fil 2009 - Double-licensed under the GNU/LGPL and MIT licenses
10// http://zzz.rezo.net/-SPIP-
11// $ttl = time to live
12// $vars = other variables that could change the result
13// (the function's variables are automatically taken into account)
14//
15// Usage: require_once 'xcache.php';
16// In any cacheable function add at top:
17// if(!is_null($c=cache_me())) return$c;
18if (!function_exists('debug_backtrace')) {
19        function cache_me() {return;}
20} else {
21        function cache_me($vars=null, $ttl=3600) {
22                $trace = debug_backtrace();
23                $trace = $trace[1];
24                $key = md5(
25                        $trace['function']
26                        .serialize($trace['args'])
27                        .serialize($vars)
28                );
29                if (!cache_isset($key)) {
30                        cache_set($key, null, $ttl);
31                        $r = call_user_func_array($trace['function'], $trace['args']);
32                        cache_set($key, $r, $ttl);
33                        return $r;
34                }
35                return cache_get($key);
36        }
37}
38
39?>
Note: See TracBrowser for help on using the repository browser.