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
324
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 0.0.14 to 0.0.15

.eslintrc

2

package.json

@@ -24,3 +24,3 @@ {

},
"version": "0.0.14"
"version": "0.0.15"
}
import { CacheManager } from '../service';
import * as LRU from 'lru-cache';
import { Class } from '@travetto/registry';
export function Cacheable<U>(config: string | LRU.Options<string, U> & { name?: string }, keyFn?: (...args: any[]) => string) {
return (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<(...args: any[]) => U>) => {
type TypedMethodDecorator<U> = (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<(...args: any[]) => U>) => void;
export function Cacheable<U>(config: LRU.Options<string, U> & { name?: string, dispose: (k: string, v: U) => any }, keyFn?: (...args: any[]) => string): TypedMethodDecorator<U>;
export function Cacheable(config: string | LRU.Options<string, any> & { name?: string }, keyFn?: (...args: any[]) => string): TypedMethodDecorator<any>;
export function Cacheable(config: string | LRU.Options<string, any> & { name?: string }, keyFn?: (...args: any[]) => string): TypedMethodDecorator<any> {
return (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<(...args: any[]) => any>) => {
const targetName = `${target.name}-${propertyKey}`;

@@ -13,6 +18,6 @@ if (typeof config !== 'string') {

const orig = descriptor.value! as any as (...args: any[]) => U;
const orig = descriptor.value! as any as (...args: any[]) => any;
const cache = CacheManager.get<any>(config as any);
descriptor.value = function (this: any, ...args: any[]): U {
descriptor.value = function (this: any, ...args: any[]): any {
let key = keyFn ? keyFn(args) : JSON.stringify(args || []);

@@ -19,0 +24,0 @@ key = `${targetName}||${key}`;

import * as LRU from 'lru-cache';
export class CacheManager {
public static caches = new Map<string, LRU.Cache<string, any>>();
protected static defaultConfig = {

@@ -10,2 +8,4 @@ max: 1000

public static caches = new Map<string, LRU.Cache<string, any>>();
static get<T>(config: string | LRU.Options<string, T> & { name: string }) {

@@ -12,0 +12,0 @@ if (typeof config === 'string') {

@@ -8,2 +8,2 @@ export const init = {

}
}
};

@@ -8,4 +8,9 @@ import { Cacheable, CacheManager } from '../src';

constructor() { }
@Cacheable({
max: 5
max: 5,
dispose: (k: string, v: Promise<number>) => {
}
})

@@ -12,0 +17,0 @@ async smallAndComplex(num: number) {

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