@travetto/cache
Advanced tools
Comparing version 4.1.3 to 5.0.0-rc.0
{ | ||
"name": "@travetto/cache", | ||
"version": "4.1.3", | ||
"version": "5.0.0-rc.0", | ||
"description": "Caching functionality with decorators for declarative use.", | ||
@@ -28,8 +28,8 @@ "keywords": [ | ||
"dependencies": { | ||
"@travetto/di": "^4.1.1", | ||
"@travetto/model": "^4.1.3" | ||
"@travetto/di": "^5.0.0-rc.0", | ||
"@travetto/model": "^5.0.0-rc.0" | ||
}, | ||
"peerDependencies": { | ||
"@travetto/test": "^4.1.1", | ||
"@travetto/transformer": "^4.1.1" | ||
"@travetto/test": "^5.0.0-rc.0", | ||
"@travetto/transformer": "^5.0.0-rc.0" | ||
}, | ||
@@ -36,0 +36,0 @@ "peerDependenciesMeta": { |
@@ -29,3 +29,3 @@ <!-- This file was generated by @travetto/doc and should not be modified directly --> | ||
Currently, the following are packages that provide [Expiry](https://github.com/travetto/travetto/tree/main/module/model/src/service/expiry.ts#L11): | ||
* [Data Modeling Support](https://github.com/travetto/travetto/tree/main/module/model#readme "Datastore abstraction for core operations.") - @travetto/model: [FileModelService](https://github.com/travetto/travetto/tree/main/module/model/src/provider/file.ts#L50), [MemoryModelService](https://github.com/travetto/travetto/tree/main/module/model/src/provider/memory.ts#L53) | ||
* [Data Modeling Support](https://github.com/travetto/travetto/tree/main/module/model#readme "Datastore abstraction for core operations.") - @travetto/model: [FileModelService](https://github.com/travetto/travetto/tree/main/module/model/src/provider/file.ts#L50), [MemoryModelService](https://github.com/travetto/travetto/tree/main/module/model/src/provider/memory.ts#L54) | ||
* [DynamoDB Model Support](https://github.com/travetto/travetto/tree/main/module/model-dynamodb#readme "DynamoDB backing for the travetto model module.") - @travetto/model-dynamodb | ||
@@ -43,5 +43,5 @@ * [Elasticsearch Model Source](https://github.com/travetto/travetto/tree/main/module/model-elasticsearch#readme "Elasticsearch backing for the travetto model module, with real-time modeling support for Elasticsearch mappings.") - @travetto/model-elasticsearch | ||
Additionally, to use the decorators you will need to have a [CacheService](https://github.com/travetto/travetto/tree/main/module/cache/src/service.ts#L29) object accessible on the class instance. This can be dependency injected, or manually constructed. The decorators will detect the field at time of method execution, which decouples construction of your class from the cache construction. | ||
Additionally, to use the decorators you will need to have a [CacheService](https://github.com/travetto/travetto/tree/main/module/cache/src/service.ts#L35) object accessible on the class instance. This can be dependency injected, or manually constructed. The decorators will detect the field at time of method execution, which decouples construction of your class from the cache construction. | ||
[@Cache](https://github.com/travetto/travetto/tree/main/module/cache/src/decorator.ts#L13) is a decorator that will cache all successful results, keyed by a computation based on the method arguments. Given the desire for supporting remote caches (e.g. [redis](https://redis.io), [memcached](https://memcached.org)), only asynchronous methods are supported. | ||
[@Cache](https://github.com/travetto/travetto/tree/main/module/cache/src/decorator.ts#L16) is a decorator that will cache all successful results, keyed by a computation based on the method arguments. Given the desire for supporting remote caches (e.g. [redis](https://redis.io), [memcached](https://memcached.org)), only asynchronous methods are supported. | ||
@@ -74,3 +74,3 @@ **Code: Using decorators to cache expensive async call** | ||
### Cache | ||
The [@Cache](https://github.com/travetto/travetto/tree/main/module/cache/src/decorator.ts#L13) decorator supports configurations on: | ||
The [@Cache](https://github.com/travetto/travetto/tree/main/module/cache/src/decorator.ts#L16) decorator supports configurations on: | ||
* `name` the field name of the current class which points to the desired cache source. | ||
@@ -88,3 +88,3 @@ * `config` the additional/optional config options, on a per invocation basis | ||
### EvictCache | ||
Additionally, there is support for planned eviction via the [@EvictCache](https://github.com/travetto/travetto/tree/main/module/cache/src/decorator.ts#L40) decorator. On successful execution of a method with this decorator, the matching keySpace/key value will be evicted from the cache. This requires coordination between multiple methods, to use the same `keySpace` and `key` to compute the expected key. | ||
Additionally, there is support for planned eviction via the [@EvictCache](https://github.com/travetto/travetto/tree/main/module/cache/src/decorator.ts#L43) decorator. On successful execution of a method with this decorator, the matching keySpace/key value will be evicted from the cache. This requires coordination between multiple methods, to use the same `keySpace` and `key` to compute the expected key. | ||
@@ -125,3 +125,3 @@ **Code: Using decorators to cache/evict user access** | ||
## Extending the Cache Service | ||
By design, the [CacheService](https://github.com/travetto/travetto/tree/main/module/cache/src/service.ts#L29) relies solely on the [Data Modeling Support](https://github.com/travetto/travetto/tree/main/module/model#readme "Datastore abstraction for core operations.") module. Specifically on the [Expiry](https://github.com/travetto/travetto/tree/main/module/model/src/service/expiry.ts#L11). This combines basic support for CRUD as well as knowledge of how to manage expirable content. Any model service that honors these contracts is a valid candidate to power the [CacheService](https://github.com/travetto/travetto/tree/main/module/cache/src/service.ts#L29). The [CacheService](https://github.com/travetto/travetto/tree/main/module/cache/src/service.ts#L29) is expecting the model service to be registered using the @travetto/cache:model: | ||
By design, the [CacheService](https://github.com/travetto/travetto/tree/main/module/cache/src/service.ts#L35) relies solely on the [Data Modeling Support](https://github.com/travetto/travetto/tree/main/module/model#readme "Datastore abstraction for core operations.") module. Specifically on the [Expiry](https://github.com/travetto/travetto/tree/main/module/model/src/service/expiry.ts#L11). This combines basic support for CRUD as well as knowledge of how to manage expirable content. Any model service that honors these contracts is a valid candidate to power the [CacheService](https://github.com/travetto/travetto/tree/main/module/cache/src/service.ts#L35). The [CacheService](https://github.com/travetto/travetto/tree/main/module/cache/src/service.ts#L35) is expecting the model service to be registered using the @travetto/cache:model: | ||
@@ -128,0 +128,0 @@ **Code: Registering a Custom Model Source** |
@@ -1,2 +0,2 @@ | ||
import { MethodDescriptor, TimeSpan, TimeUtil } from '@travetto/base'; | ||
import { TimeSpan, TimeUtil } from '@travetto/base'; | ||
@@ -7,2 +7,5 @@ import { CacheService } from './service'; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
type MethodDescriptor<R = any, V = unknown> = TypedPropertyDescriptor<(this: V, ...params: any[]) => R>; | ||
/** | ||
@@ -21,3 +24,3 @@ * Indicates a method is intended to cache. The return type must be properly serializable | ||
if (typeof cfg === 'string' || typeof cfg === 'number') { | ||
config.maxAge = TimeUtil.timeToMs(cfg); | ||
config.maxAge = TimeUtil.asMillis(cfg); | ||
} else { | ||
@@ -24,0 +27,0 @@ config = cfg; |
import { ExpiresAt, Index, Model, ModelExpirySupport, NotFoundError } from '@travetto/model'; | ||
import { Text } from '@travetto/schema'; | ||
import { Inject, Injectable } from '@travetto/di'; | ||
import { AppError, Env } from '@travetto/base'; | ||
import { AppError, Env, TimeUtil } from '@travetto/base'; | ||
import { isIndexedSupported, isStorageSupported } from '@travetto/model/src/internal/service/common'; | ||
@@ -13,3 +13,3 @@ | ||
const INFINITE_MAX_AGE = '5000-01-01'; | ||
const INFINITE_MAX_AGE = TimeUtil.asMillis(10, 'y'); | ||
@@ -72,3 +72,3 @@ @Index({ | ||
id, | ||
expiresAt: new Date(Date.now() + maxAge), | ||
expiresAt: TimeUtil.fromNow(maxAge), | ||
issuedAt: new Date() | ||
@@ -96,3 +96,3 @@ }); // Do not wait | ||
keySpace, | ||
expiresAt: new Date(maxAge ? maxAge + Date.now() : INFINITE_MAX_AGE), | ||
expiresAt: TimeUtil.fromNow(maxAge || INFINITE_MAX_AGE), | ||
issuedAt: new Date() | ||
@@ -99,0 +99,0 @@ }), |
@@ -1,4 +0,3 @@ | ||
import crypto from 'node:crypto'; | ||
import { Util } from '@travetto/base'; | ||
import { ObjectUtil } from '@travetto/base'; | ||
import { CoreCacheConfig } from './types'; | ||
@@ -18,3 +17,3 @@ | ||
const replacer = all ? | ||
((key: string, val: unknown): unknown => (val && val instanceof RegExp) ? val.source : (ObjectUtil.isFunction(val) ? val.toString() : val)) : | ||
((key: string, val: unknown): unknown => (val && val instanceof RegExp) ? val.source : (typeof val === 'function' ? val.toString() : val)) : | ||
undefined; | ||
@@ -40,4 +39,4 @@ | ||
const key = `${config.keySpace!}_${this.toSafeJSON(keyParams)}`; | ||
return crypto.createHash('sha1').update(key).digest('hex').substring(0, 32); // Force to uuid | ||
return Util.hash(key, 32); | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
31320
562
1
+ Added@travetto/config@5.1.0(transitive)
+ Added@travetto/di@5.1.0(transitive)
+ Added@travetto/manifest@5.1.0(transitive)
+ Added@travetto/model@5.1.0(transitive)
+ Added@travetto/registry@5.1.0(transitive)
+ Added@travetto/runtime@5.1.0(transitive)
+ Added@travetto/schema@5.1.0(transitive)
+ Added@travetto/terminal@5.1.0(transitive)
+ Added@travetto/test@5.1.0(transitive)
+ Added@travetto/transformer@5.1.0(transitive)
+ Added@travetto/worker@5.1.0(transitive)
+ Added@types/node@22.13.4(transitive)
+ Addedundici-types@6.20.0(transitive)
+ Addedyaml@2.7.0(transitive)
- Removed@travetto/base@4.1.2(transitive)
- Removed@travetto/config@4.1.2(transitive)
- Removed@travetto/di@4.1.1(transitive)
- Removed@travetto/manifest@4.1.0(transitive)
- Removed@travetto/model@4.1.4(transitive)
- Removed@travetto/registry@4.1.2(transitive)
- Removed@travetto/schema@4.1.1(transitive)
- Removed@travetto/terminal@4.1.1(transitive)
- Removed@travetto/test@4.1.1(transitive)
- Removed@travetto/transformer@4.1.2(transitive)
- Removed@travetto/worker@4.1.1(transitive)
- Removed@travetto/yaml@4.1.1(transitive)
- Removed@types/node@20.17.19(transitive)
- Removedundici-types@6.19.8(transitive)
Updated@travetto/di@^5.0.0-rc.0
Updated@travetto/model@^5.0.0-rc.0