Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@travetto/cache

Package Overview
Dependencies
Maintainers
1
Versions
325
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@travetto/cache - npm Package Compare versions

Comparing version 1.0.0-beta.4 to 1.0.0-beta.5

config/decorator.yml

8

package.json

@@ -31,4 +31,6 @@ {

"index.ts",
"config",
"extension",
"src"
"src",
"support"
],

@@ -39,4 +41,4 @@ "name": "@travetto/cache",

},
"version": "1.0.0-beta.4",
"gitHead": "d817f2e0f0420f9de1b74bad3714ac96b07f1eaa"
"version": "1.0.0-beta.5",
"gitHead": "1bd9e718edd9682f0cb5c30a3197fcec1c16ae62"
}

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

import { ValidCacheFields, CacheStore } from './store/types';
import { ValidCacheFields } from './store/types';
import { CoreCacheConfig, CacheConfig } from './types';

@@ -6,58 +6,8 @@

function generateKey(cache: CacheStore, config: CoreCacheConfig, params: any[]) {
const input = config.params ? config.params(params) : params;
const keyParams = config.key ? config.key(...input) : input;
return cache.computeKey(keyParams);
}
function initConfig(config: CoreCacheConfig, target: any, fn: Function) {
if (!config.keySpace) {
config.keySpace = `${target.constructor.name}.${fn.name}`;
}
}
export function Cache<U extends any>(field: ValidCacheFields<U>, config: CacheConfig = {}): TypedMethodDecorator<U, Promise<any>> {
return function (target: U, propertyKey: string, descriptor: TypedPropertyDescriptor<(...params: any[]) => Promise<any>>) {
const og = descriptor.value!;
initConfig(config, target, og);
descriptor.value = async function (this: U, ...params: any[]) {
const cache = this[field] as any as CacheStore;
const key = generateKey(cache, config, params);
let res = await cache.getOptional(config, key);
if (res === undefined) {
let data = await og.apply(this, params);
if (config.serialize) {
data = config.serialize(data);
}
res = (await cache.setWithAge(config, { key, data })).data;
}
if (config.deserialize) {
res = config.deserialize(res);
}
return res;
};
Object.defineProperty(descriptor.value, 'name', { value: propertyKey });
};
return function (target: U, propertyKey: string, descriptor: TypedPropertyDescriptor<(...params: any[]) => Promise<any>>) { }
}
export function EvictCache<U extends any>(field: ValidCacheFields<U>, config: CoreCacheConfig = {}): TypedMethodDecorator<U, Promise<any>> {
return function (target: U, propertyKey: string, descriptor: TypedPropertyDescriptor<(...params: any[]) => Promise<any>>) {
const og = descriptor.value!;
initConfig(config, target, og);
descriptor.value = async function (this: U, ...params: any[]) {
const cache = this[field] as any as CacheStore;
const key = generateKey(cache, config, params);
const val = await og.apply(this, params);
await cache.delete(key);
return val;
};
Object.defineProperty(descriptor.value, 'name', { value: propertyKey });
};
return function (target: U, propertyKey: string, descriptor: TypedPropertyDescriptor<(...params: any[]) => Promise<any>>) { };
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc