New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@travetto/cache

Package Overview
Dependencies
Maintainers
0
Versions
330
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 4.1.3 to 5.0.0-rc.0

10

package.json
{
"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

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