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

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

renomer W() en Cache() pour etre moins cryptique

File size: 950 bytes
Line 
1<?php
2
3//
4// Cache function W()
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: if (null!==$W=W())return$W;
13
14if (!function_exists('Cache')) {
15
16# xcache ?
17if (function_exists('xcache_set')) {
18        function Cache($vars=null, $ttl=3600) {
19                $trace = debug_backtrace();
20                $trace = $trace[1];
21                $key = __FILE__ . md5(
22                        $trace['function']
23                        .serialize($trace['args'])
24                        .serialize($vars)
25                );
26                if (!xcache_isset($key)) {
27                        xcache_set($key, null, $ttl);
28                        $r = call_user_func_array($trace['function'], $trace['args']);
29                        xcache_set($key, $r, $ttl);
30                        return $r;
31                }
32                return xcache_get($key);
33        }
34}
35# elementary compatibility
36else {
37        function Cache(){return null;}
38}
39
40}
41
42?>
Note: See TracBrowser for help on using the repository browser.