Caching infrastructure and memory management for the ziegel platform. Provides multiple cache implementations, eviction policies, cache factories, and memory-efficient caching strategies for enterprise applications.
Caching: Enterprise caching with multiple strategies, eviction policies, and memory management for high-performance applications.
🚀 Overview
@breadstone/ziegel-platform-caching provides:
- Multiple Cache Types: Session, transient, and infinite caching strategies
- Eviction Policies: Configurable cache eviction and cleanup policies
- Cache Factory: Factory pattern for creating and managing cache instances
- Cache Items: Wrapper objects for cached data with metadata
- Caching Modes: Different caching behaviors and strategies
- Memory Management: Efficient memory usage and garbage collection support
📦 Installation
bash
npm install @breadstone/ziegel-platform-caching
# or
yarn add @breadstone/ziegel-platform-caching🧩 Features & Usage Examples
Basic Caching
typescript
import { CacheManager, MemoryCache } from '@breadstone/ziegel-platform-caching';
const cache = new MemoryCache();
const cacheManager = new CacheManager(cache);
// Set cache value
await cacheManager.set('user:123', userData, { ttl: 3600 });
// Get cache value
const user = await cacheManager.get<User>('user:123');
// Remove from cache
await cacheManager.remove('user:123');Cache Decorators
typescript
import { Cacheable, CacheEvict } from '@breadstone/ziegel-platform-caching';
class UserService {
@Cacheable('users', { ttl: 3600 })
async getUser(id: string): Promise<User> {
return await this.userRepository.findById(id);
}
@CacheEvict('users')
async updateUser(id: string, data: Partial<User>): Promise<User> {
return await this.userRepository.update(id, data);
}
}Multi-Level Cache
typescript
import { MultiLevelCache, MemoryCache, StorageCache, RedisCache } from '@breadstone/ziegel-platform-caching';
const l1 = new MemoryCache({ maxSize: 1000 });
const l2 = new StorageCache({ storageKey: 'app-cache' });
const l3 = new RedisCache({ host: 'redis-server' });
const multiCache = new MultiLevelCache([l1, l2, l3]);Cache Strategies
typescript
import { LRUCacheStrategy, TTLCacheStrategy, CompositeCacheStrategy } from '@breadstone/ziegel-platform-caching';
const lruStrategy = new LRUCacheStrategy({ maxSize: 1000 });
const ttlStrategy = new TTLCacheStrategy({ defaultTtl: 3600 });
const strategy = new CompositeCacheStrategy([lruStrategy, ttlStrategy]);Distributed Caching
typescript
import { DistributedCache, RedisProvider } from '@breadstone/ziegel-platform-caching';
const redisProvider = new RedisProvider({
host: 'cache-cluster.example.com',
port: 6379,
cluster: true,
});
const distributedCache = new DistributedCache(redisProvider);
await distributedCache.set('global:config', config);Cache Metrics
typescript
import { CacheMetrics, CacheAnalytics } from '@breadstone/ziegel-platform-caching';
const metrics = new CacheMetrics();
const analytics = new CacheAnalytics(metrics);
// Get cache statistics
const stats = analytics.getStatistics();
console.log(`Hit Rate: ${stats.hitRate}%`);
console.log(`Miss Count: ${stats.missCount}`);📚 Package import points
typescript
import {
// Core Caching
CacheManager,
ICache,
CacheEntry,
// Cache Implementations
MemoryCache,
StorageCache,
RedisCache,
MultiLevelCache,
// Strategies
LRUCacheStrategy,
TTLCacheStrategy,
CompositeCacheStrategy,
// Decorators
Cacheable,
CacheEvict,
CacheInvalidate,
// Distributed
DistributedCache,
RedisProvider,
// Metrics
CacheMetrics,
CacheAnalytics,
} from '@breadstone/ziegel-platform-caching';📚 API Documentation
Related Packages
- @breadstone/ziegel-platform: Core platform services
- @breadstone/ziegel-core: Foundation utilities
- @breadstone/ziegel-platform-configuration: Configuration management
License
MIT
Issues
Please report bugs and feature requests in the Issue Tracker
Part of the ziegel Enterprise TypeScript Framework