功能:同步小程序流程
This commit is contained in:
@@ -1,15 +1,39 @@
|
||||
/**
|
||||
* Purpose: CACHE_PREFIX supports cache.js by holding or executing the cache prefix page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const CACHE_PREFIX = 'miniCache:'
|
||||
/**
|
||||
* Purpose: memoryCache supports cache.js by holding or executing the memory cache page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const memoryCache = {}
|
||||
/**
|
||||
* Purpose: inflightCache supports cache.js by holding or executing the inflight cache page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const inflightCache = {}
|
||||
|
||||
/**
|
||||
* Purpose: now supports cache.js by holding or executing the now page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function now() {
|
||||
return Date.now()
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: buildKey supports cache.js by holding or executing the build key page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function buildKey(key) {
|
||||
return `${CACHE_PREFIX}${key}`
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: clearExpiredEntry supports cache.js by holding or executing the clear expired entry page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function clearExpiredEntry(key, entry) {
|
||||
if (!entry) {
|
||||
return
|
||||
@@ -22,6 +46,10 @@ function clearExpiredEntry(key, entry) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: getCache supports cache.js by holding or executing the get cache page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function getCache(key, defaultValue) {
|
||||
if (!key) {
|
||||
return defaultValue
|
||||
@@ -45,6 +73,10 @@ function getCache(key, defaultValue) {
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: setCache supports cache.js by holding or executing the set cache page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function setCache(key, value, ttlMs) {
|
||||
if (!key) {
|
||||
return value
|
||||
@@ -61,6 +93,10 @@ function setCache(key, value, ttlMs) {
|
||||
return value
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: removeCache supports cache.js by holding or executing the remove cache page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function removeCache(key) {
|
||||
if (!key) {
|
||||
return
|
||||
@@ -71,6 +107,10 @@ function removeCache(key) {
|
||||
} catch (error) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: removeByPrefix supports cache.js by holding or executing the remove by prefix page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function removeByPrefix(prefix) {
|
||||
Object.keys(memoryCache).forEach(key => {
|
||||
if (key.startsWith(prefix)) {
|
||||
@@ -82,6 +122,10 @@ function removeByPrefix(prefix) {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: remember supports cache.js by holding or executing the remember page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function remember(key, ttlMs, loader) {
|
||||
const cached = getCache(key, undefined)
|
||||
if (cached !== undefined) {
|
||||
|
||||
Reference in New Issue
Block a user