diff options
author | Andrew Manning <tamanning@zoho.com> | 2016-06-25 06:30:15 -0500 |
---|---|---|
committer | Andrew Manning <tamanning@zoho.com> | 2016-06-25 06:30:15 -0500 |
commit | 83a42afddf6e5ffd04028431b36aed6ecadf5b9d (patch) | |
tree | 26d7251cd032fb627c80345cc9cbc4384a66f46f /Zotlabs/Lib/Cache.php | |
parent | 780f83a118146cf67509574ac88024c2cb03cf3a (diff) | |
parent | ec3651d216a5eafcb8019825bc6751e6ffa8c198 (diff) | |
download | volse-hubzilla-83a42afddf6e5ffd04028431b36aed6ecadf5b9d.tar.gz volse-hubzilla-83a42afddf6e5ffd04028431b36aed6ecadf5b9d.tar.bz2 volse-hubzilla-83a42afddf6e5ffd04028431b36aed6ecadf5b9d.zip |
Merge remote-tracking branch 'upstream/dev' into wiki
Diffstat (limited to 'Zotlabs/Lib/Cache.php')
-rw-r--r-- | Zotlabs/Lib/Cache.php | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/Zotlabs/Lib/Cache.php b/Zotlabs/Lib/Cache.php new file mode 100644 index 000000000..35c8f56ad --- /dev/null +++ b/Zotlabs/Lib/Cache.php @@ -0,0 +1,46 @@ +<?php /** @file */ + +namespace Zotlabs\Lib; + + /** + * cache api + */ + +class Cache { + public static function get($key) { + $r = q("SELECT v FROM cache WHERE k = '%s' limit 1", + dbesc($key) + ); + + if ($r) + return $r[0]['v']; + return null; + } + + public static function set($key,$value) { + + $r = q("SELECT * FROM cache WHERE k = '%s' limit 1", + dbesc($key) + ); + if($r) { + q("UPDATE cache SET v = '%s', updated = '%s' WHERE k = '%s'", + dbesc($value), + dbesc(datetime_convert()), + dbesc($key)); + } + else { + q("INSERT INTO cache ( k, v, updated) VALUES ('%s','%s','%s')", + dbesc($key), + dbesc($value), + dbesc(datetime_convert())); + } + } + + + public static function clear() { + q("DELETE FROM cache WHERE updated < '%s'", + dbesc(datetime_convert('UTC','UTC',"now - 30 days"))); + } + +} + |