]> git.mxchange.org Git - friendica.git/blob - include/cache.php
Merge branch 'master', remote-tracking branch 'remotes/upstream/master'
[friendica.git] / include / cache.php
1 <?php
2         /**
3          *  cache api
4          */
5          
6         class Cache {
7                 public static function get($key){
8                         $r = q("SELECT `v` FROM `cache` WHERE `k`='%s' limit 1",
9                                 dbesc($key)
10                         );
11                         
12                         if (count($r)) return $r[0]['v'];
13                         return null;
14                 }
15                 
16                 public static function set($key,$value) {
17                         $r = q("SELECT * FROM `cache` WHERE `k`='%s' limit 1",
18                                 dbesc($key)
19                         );
20                         if(count($r)) {
21                                 q("UPDATE `cache` SET `v` = '%s', `updated = '%s' WHERE `k` = '%s' limit 1",
22                                         dbesc($value),
23                                         dbesc(datetime_convert()),
24                                         dbesc($key));
25                         }
26                         else {
27                                 q("INSERT INTO `cache` (`k`,`v`,`updated`) VALUES ('%s','%s','%s')",
28                                         dbesc($key),
29                                         dbesc($value),
30                                         dbesc(datetime_convert()));
31                         }
32                 }
33                 
34                 public static function clear(){
35                         q("DELETE FROM `cache` WHERE `updated` < '%s'",
36                                 dbesc(datetime_convert('UTC','UTC',"now - 30 days")));                  
37                 }
38                 
39         }
40