mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-24 07:26:50 +00:00
本地开发、开启文件缓存
This commit is contained in:
8
lib/cache/local_file_cache.js
vendored
8
lib/cache/local_file_cache.js
vendored
@@ -6,7 +6,7 @@ const cacheInvalidSeconds = 1000000000 * 1000
|
||||
// 文件名
|
||||
const jsonFile = path.resolve('./data.json')
|
||||
|
||||
export async function getCacheFromFile (key) {
|
||||
export async function getCache (key) {
|
||||
const exist = await fs.existsSync(jsonFile)
|
||||
if (!exist) return null
|
||||
const data = await fs.readFileSync(jsonFile)
|
||||
@@ -33,7 +33,7 @@ export async function getCacheFromFile (key) {
|
||||
* @param data
|
||||
* @returns {Promise<null>}
|
||||
*/
|
||||
export async function setCacheToFile (key, data) {
|
||||
export async function setCache (key, data) {
|
||||
const exist = await fs.existsSync(jsonFile)
|
||||
const json = exist ? JSON.parse(await fs.readFileSync(jsonFile)) : {}
|
||||
json[key] = data
|
||||
@@ -41,10 +41,12 @@ export async function setCacheToFile (key, data) {
|
||||
fs.writeFileSync(jsonFile, JSON.stringify(json))
|
||||
}
|
||||
|
||||
export async function delCacheFromFile (key, data) {
|
||||
export async function delCache (key, data) {
|
||||
const exist = await fs.existsSync(jsonFile)
|
||||
const json = exist ? JSON.parse(await fs.readFileSync(jsonFile)) : {}
|
||||
delete json.key
|
||||
json[key + '_expire_time'] = new Date().getTime()
|
||||
fs.writeFileSync(jsonFile, JSON.stringify(json))
|
||||
}
|
||||
|
||||
export default { getCache, setCache, delCache }
|
||||
|
||||
Reference in New Issue
Block a user