Got questions, comments, patches, etc.?
Contact Jason Woofenden
gitweb
/
wfpl.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
add db_upgrade(), persistent_invalidate_cache()
[wfpl.git]
/
persistent.php
diff --git
a/persistent.php
b/persistent.php
index
17005b6
..
c471322
100644
(file)
--- a/
persistent.php
+++ b/
persistent.php
@@
-5,19
+5,20
@@
# 1.0 Universal public domain dedication, which can be found at
# http://creativecommons.org/publicdomain/zero/1.0/
# 1.0 Universal public domain dedication, which can be found at
# http://creativecommons.org/publicdomain/zero/1.0/
-# a simple, persistent, key/value store optimized for many reads
+# a simple, persistent, key/value store optimized for many reads and small data
#
# call persistent_{get,set,clear}
# for internal use
#
# call persistent_{get,set,clear}
# for internal use
+# IF YOU CHANGE THIS: change the version in db_upgrade() too
function persistent_init() {
if (isset($GLOBALS['wfpl_persistent'])) {
return;
}
$GLOBALS['wfpl_persistent'] = array();
function persistent_init() {
if (isset($GLOBALS['wfpl_persistent'])) {
return;
}
$GLOBALS['wfpl_persistent'] = array();
- $rows = db_get_rows('persistent', 'k,v');
+ $rows = db_get_assocs('wfpl_persistent', 'k,v');
foreach ($rows as &$row) {
foreach ($rows as &$row) {
- $GLOBALS['wfpl_persistent'][$row[0]] = json_decode($row[1], true);
+ $GLOBALS['wfpl_persistent'][$row['k']] = json_decode($row['v'], true);
} unset($row);
}
} unset($row);
}
@@
-34,10
+35,8
@@
function persistent_set($k, $v) {
if ($GLOBALS['wfpl_persistent'][$k] === $v) {
return;
}
if ($GLOBALS['wfpl_persistent'][$k] === $v) {
return;
}
- db_update('persistent', 'v', json_encode($v), 'where k=%"', $k);
- } else {
- db_insert('persistent', 'k,v', $k, json_encode($v));
}
}
+ db_replace('wfpl_persistent', 'k,v', $k, json_encode($v));
$GLOBALS['wfpl_persistent'][$k] = $v;
}
function persistent_clear($k) {
$GLOBALS['wfpl_persistent'][$k] = $v;
}
function persistent_clear($k) {
@@
-47,3
+46,11
@@
function persistent_clear($k) {
unset($GLOBALS['wfpl_persistent'][$k]);
}
}
unset($GLOBALS['wfpl_persistent'][$k]);
}
}
+
+function persistent_invalidate_cache() {
+ if (isset($GLOBALS['wfpl_persistent'])) {
+ unset($GLOBALS['wfpl_persistent']);
+ }
+ return;
+}
+