mirror of
https://github.com/wassname/talk.git
synced 2026-09-10 12:43:11 +08:00
added support for deep route caching, settings cache, template optim
This commit is contained in:
+6
-4
@@ -21,7 +21,7 @@ const keyfunc = (key) => {
|
||||
* This wraps a complicated function with a cache, in the event that the item is
|
||||
* not inside the cache, it will perform the work to get it and then set it
|
||||
* followed by returning the value.
|
||||
* @param {Mixed} key Either an array of items or string represening this
|
||||
* @param {Mixed} key Either an array of items or string representing this
|
||||
* work
|
||||
* @param {Integer} expiry Time in seconds for the cache entry to live for
|
||||
* @param {Function} work A function that returns a promise that can be
|
||||
@@ -30,7 +30,7 @@ const keyfunc = (key) => {
|
||||
*/
|
||||
cache.wrap = async (key, expiry, work, kf = keyfunc) => {
|
||||
let value = await cache.get(key, kf);
|
||||
if (value !== null) {
|
||||
if (typeof value !== 'undefined' && value !== null) {
|
||||
debug('wrap: hit', kf(key));
|
||||
return value;
|
||||
}
|
||||
@@ -187,11 +187,13 @@ cache.wrapMany = async (keys, expiry, work, kf = keyfunc) => {
|
||||
* @return {Promise}
|
||||
*/
|
||||
cache.get = async (key, kf = keyfunc) => cache.client.get(kf(key)).then((reply) => {
|
||||
if (reply !== null) {
|
||||
if (typeof reply !== 'undefined' && reply !== null) {
|
||||
|
||||
// Parse the stored cache value from JSON.
|
||||
return JSON.parse(reply);
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -207,7 +209,7 @@ cache.getMany = async (keys, kf = keyfunc) => cache.client.mget(keys.map(kf)).th
|
||||
for (let i = 0; i < replies.length; i++) {
|
||||
let value = null;
|
||||
|
||||
if (replies[i] != null) {
|
||||
if (typeof replies[i] !== 'undefined' && replies[i] !== null) {
|
||||
|
||||
// Parse the stored cache value from JSON.
|
||||
value = JSON.parse(replies[i]);
|
||||
|
||||
Reference in New Issue
Block a user