🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

req-caching

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

req-caching - npm Package Compare versions

Comparing version

to
1.0.10

2

package.json
{
"name": "req-caching",
"version": "1.0.9",
"version": "1.0.10",
"type": "module",

@@ -5,0 +5,0 @@ "types": "lib",

export type CACHE_TYPE = "memory" | "cookie" | "localstorage"
export interface CACHE_OPTS {
maxAge?: number
maxAge?: {
seconds?: number
minutes?: number
hours?: number
}
strict?: boolean
encrypt?: boolean
}

@@ -21,2 +26,7 @@

export interface CACHE_DRIVER {
save: () => Promise<any>
get: () => Promise<any>
}
export const after_time: any = (t: any) => {

@@ -23,0 +33,0 @@ if (t.seconds) {

@@ -1,2 +0,2 @@

import { CACHE_VALUE, after_time } from "./defined"
import { CACHE_VALUE, CACHE_DRIVER, after_time, CACHE_OPTS } from "./defined"

@@ -21,4 +21,3 @@ const driver = {

localstorage: {
save: async (key: string, v: any, time: any) => {
if (time === undefined) time = { seconds: 60 }
save: async (key: string, v: any, opts: CACHE_OPTS) => {
try {

@@ -28,3 +27,3 @@ key = `_CACHE_${key}`

value: v,
expires: after_time(time),
expires: after_time(opts.maxAge),
}

@@ -31,0 +30,0 @@ localStorage.setItem(key, JSON.stringify(value))

@@ -24,3 +24,15 @@ import {

/**
* @param {string} key
* @param {()=>any} seed
* @param {CACHE_OPTS} options
* @returns {void}
*/
async add(key: string, seed: () => any, options: CACHE_OPTS) {
options = {
maxAge: options.maxAge || { seconds: 60 },
strict: options.strict || false,
encrypt: options.encrypt || false,
}
this.bunch.push({

@@ -34,2 +46,6 @@ key,

/**
* @param {string} key
* @return {any} value
*/
async get(key: string) {

@@ -42,6 +58,8 @@ let temp = await this.driver.get(key)

if (indexer === undefined) {
return null
return new Error("NO CACHE FOUND")
}
temp = indexer.seed()
await this.driver.save(key, temp, indexer.options?.maxAge)
if (!(await this.driver.save(key, temp, indexer.options))) {
return new Error("CACHE_SAVE FAILED")
}
}

@@ -48,0 +66,0 @@ return temp