@travetto/cache
Advanced tools
Comparing version 0.0.16 to 0.0.17
@@ -24,3 +24,3 @@ { | ||
}, | ||
"version": "0.0.16" | ||
"version": "0.0.17" | ||
} |
travetto: Cache | ||
=== | ||
Provides a simple wrapper around `lru-cache` to provide standard caching constructs. | ||
Provides a simple wrapper around [`lru-cache`](https://github.com/isaacs/node-lru-cache) to provide standard caching constructs. | ||
Provides a decorator to allow caching at the method level throughout the system. Will rewrite the method | ||
to cache on successful responses. | ||
`@Cacheable` is a decorator that allows caching at class methods. The decorator will rewrite the method to cache on successful results. The decorator supports synchronous as well as asynchronous methods. | ||
@@ -13,4 +12,4 @@ ```typescript | ||
@Cacheable({ max: 1000 }) | ||
calculateExpensiveResult(expression: string) { | ||
... | ||
async calculateExpensiveResult(expression: string) { | ||
const value = await request(`https://google.com?q=${expression}`); | ||
return value; | ||
@@ -20,1 +19,8 @@ } | ||
``` | ||
The `@Cacheable` decorator supports certain configurations: | ||
* `name` the name of the cache space | ||
* `dispose` the function to invoke on cache eviction | ||
* `keyFn` the function used to determine the cache key, defaults to all params serialized to a string | ||
* `max` the maximum number of elements that the cache will hold before eviction | ||
* `maxAge` the longest time an element is allowed to live before eviction. Defaults to infinite. |
@@ -0,4 +1,3 @@ | ||
import * as LRU from 'lru-cache'; | ||
import { CacheManager } from '../service'; | ||
import * as LRU from 'lru-cache'; | ||
import { Class } from '@travetto/registry'; | ||
@@ -5,0 +4,0 @@ type TypedMethodDecorator<U> = (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<(...args: any[]) => U>) => void; |
@@ -106,12 +106,12 @@ import { Cacheable, CacheManager } from '../src'; | ||
const val = test.complexInput({ a: 5, b: 20 }, 20); | ||
const val2 = test.complexInput({ a: 5, b: 20 }, 20); | ||
const val3 = test.complexInput({ b: 5, a: 20 }, 20); | ||
const val = await test.complexInput({ a: 5, b: 20 }, 20); | ||
const val2 = await test.complexInput({ a: 5, b: 20 }, 20); | ||
const val3 = await test.complexInput({ b: 5, a: 20 }, 20); | ||
assert(val === val2); | ||
assert(val !== val3); | ||
const val4 = test.complexInputWithCustomKey({ a: 5, b: 20 }, 20); | ||
const val5 = test.complexInputWithCustomKey({ b: 5, a: 20 }, 30); | ||
const val4 = await test.complexInputWithCustomKey({ a: 5, b: 20 }, 20); | ||
const val5 = await test.complexInputWithCustomKey({ b: 5, a: 20 }, 30); | ||
assert(val4 === val5); | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7397
24
165