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

Last change on this file since 32408 was 32408, checked in by cedric@…, 10 years ago

commentons mieux

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