
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
@zcodeapp/cache
Advanced tools
The Cache module is a part of the @zcodeapp framework, designed to provide a flexible caching mechanism for applications. It leverages dependency injection and interfaces from the framework to create a versatile and extensible caching system. The module includes a basic MemoryStrategy for caching, but is built to accommodate different caching strategies.
Flexible Caching Strategy
The Cache class allows for changing the caching strategy at runtime, providing flexibility in how data is cached.
Memory-Based Caching
Includes a default MemoryStrategy for in-memory caching, suitable for scenarios where quick access to data is required and persistence is not a concern.
MD5 Key Transformation
Utilizes MD5 hashing for keys, ensuring consistent key formatting and potentially reducing the risk of key collisions.
Simple API
Offers a straightforward API with set and get methods for storing and retrieving data.
Logging Integration
Integrates with the @zcodeapp/logger for logging activities, aiding in debugging and monitoring.
Include the Cache class in your TypeScript project:
npm install @zcodeapp/cache
import { Di } from '@zcodeapp/di';
import { Cache } from '@zcodeapp/cache';
const di = Di.getInstance();
const cache = di.get(Cache);
await cache.set('myKey', 'myValue');
const value = await cache.get('myKey');
Cache Class
constructor(logger: Logger, cacheStrategy: MemoryStrategy): Initializes the cache with a logger and a caching strategy.changeStrategy(strategy: ICacheStrategy): void: Changes the caching strategy at runtime.async set(key: string, value: string): Promise<void>: Stores a value in the cache.async get(key: string): Promise<string>: Retrieves a value from the cache.MemoryStrategy Class
async set(key: string, value: string): Promise<void>: Stores a value in memory.async get(key: string): Promise<string>: Retrieves a value from memory.exampleStrategy.ts
import { Injectable } from "@zcodeapp/di";
import { ICacheStrategy } from "@zcodeapp/interfaces";
@Injectable()
export class ExampleStrategy implements ICacheStrategy {
public async set(key: string, value: string): Promise<void> {
// your code...
}
public async get(key: string): Promise<string> {
// your code...
}
}
main.ts
import { Di } from '@zcodeapp/di';
import { Cache } from '@zcodeapp/cache';
import { ExampleStrategy } from 'exampleStrategy';
const di = Di.getInstance();
const cache = di.get(Cache);
cache.changeStrategy(di.get(ExampleStrategy));
await cache.set('myKey', 'myValue');
const value = await cache.get('myKey');
This project is licensed under the MIT License - see the LICENSE file for details.
FAQs
Cache for application
We found that @zcodeapp/cache demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.