Skip to content

Commit 49b7540

Browse files
simllllclaude
andauthored
Add Elasticsearch and Memcached storage adapters (#14)
* feat: add Elasticsearch storage adapter Add a new @node-ts-cache/elasticsearch-storage package that provides an Elasticsearch-based storage backend for caching. The implementation uses the @elastic/elasticsearch v8 client and supports: - Basic get/set/clear operations via IAsynchronousCacheType interface - Pre-configured client injection for advanced use cases - Automatic document cleanup with refresh-wait semantics * feat: add Memcached storage adapter and update documentation Add a new @node-ts-cache/memcached-storage package that provides a Memcached-based storage backend for high-performance distributed caching. The implementation uses the memcached package and supports: - Basic get/set/clear operations via IAsynchronousCacheType interface - Single server or multi-server distributed configuration - Configurable connection options (retries, timeout, poolSize) Also updates all documentation to include both Elasticsearch and Memcached storage adapters in: - Main README.md (packages table, architecture diagram, choosing guide) - ts-cache/README.md (storage engines table) - ts-cache/ADVANCED.md (detailed configuration examples) * feat: add Valkey storage adapter and update documentation Add a new @node-ts-cache/valkey-storage package that provides a Valkey-based storage backend. Valkey is the open-source, Redis-compatible fork backed by the Linux Foundation. Features: - Basic get/set/clear operations via IAsynchronousCacheType interface - Batch operations via IMultiIAsynchronousCacheType interface - Configurable TTL with maxAge option - Error handler support for non-blocking writes - Uses iovalkey client (ioredis-compatible) Also updates all documentation to include Valkey storage adapter in: - Main README.md (packages table, architecture diagram, choosing guide) - ts-cache/README.md (storage engines table) - ts-cache/ADVANCED.md (detailed configuration examples) * Add Elasticsearch and Memcached storage adapters This changeset introduces patch versions for the core and storage adapters, including Elasticsearch and Memcached. * test: use mocks for storage adapter tests Update tests for Elasticsearch, Memcached, and Redis storage adapters to use mock clients instead of requiring real service connections. This allows tests to run in CI without needing external services. Changes: - Elasticsearch: Add MockElasticsearchClient class for testing - Memcached: Add client injection support and MockMemcached class - Redis: Add client injection support and MockRedisClient class All adapters now accept a pre-configured client in their options, which enables easy mocking for tests while maintaining backward compatibility for production use. --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent cea4fc3 commit 49b7540

26 files changed

Lines changed: 1589 additions & 52 deletions

.changeset/spotty-lions-bake.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@node-ts-cache/core": patch
3+
"@node-ts-cache/elasticsearch-storage": patch
4+
"@node-ts-cache/memcached-storage": patch
5+
"@node-ts-cache/valkey-storage": patch
6+
---
7+
8+
Add Elasticsearch and Memcached storage adapters

README.md

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,16 @@ This is a monorepo containing the following packages:
4848

4949
### Storage Adapters
5050

51-
| Package | Version | Description |
52-
| ---------------------------------------------------------- | -------------------------------------------------------------------------- | ------------------------------------------------------ |
53-
| [@node-ts-cache/redis-storage](./storages/redis) | ![npm](https://img.shields.io/npm/v/@node-ts-cache/redis-storage.svg) | Redis storage using `redis` package (v4.x) |
54-
| [@node-ts-cache/ioredis-storage](./storages/redisio) | ![npm](https://img.shields.io/npm/v/@node-ts-cache/ioredis-storage.svg) | Redis storage using `ioredis` with compression support |
55-
| [@node-ts-cache/node-cache-storage](./storages/node-cache) | ![npm](https://img.shields.io/npm/v/@node-ts-cache/node-cache-storage.svg) | In-memory cache using `node-cache` |
56-
| [@node-ts-cache/lru-storage](./storages/lru) | ![npm](https://img.shields.io/npm/v/@node-ts-cache/lru-storage.svg) | LRU cache with automatic eviction |
57-
| [@node-ts-cache/lru-redis-storage](./storages/lru-redis) | ![npm](https://img.shields.io/npm/v/@node-ts-cache/lru-redis-storage.svg) | Two-tier caching (local LRU + remote Redis) |
51+
| Package | Version | Description |
52+
| ---------------------------------------------------------------- | ----------------------------------------------------------------------------- | ------------------------------------------------------ |
53+
| [@node-ts-cache/redis-storage](./storages/redis) | ![npm](https://img.shields.io/npm/v/@node-ts-cache/redis-storage.svg) | Redis storage using `redis` package (v4.x) |
54+
| [@node-ts-cache/ioredis-storage](./storages/redisio) | ![npm](https://img.shields.io/npm/v/@node-ts-cache/ioredis-storage.svg) | Redis storage using `ioredis` with compression support |
55+
| [@node-ts-cache/node-cache-storage](./storages/node-cache) | ![npm](https://img.shields.io/npm/v/@node-ts-cache/node-cache-storage.svg) | In-memory cache using `node-cache` |
56+
| [@node-ts-cache/lru-storage](./storages/lru) | ![npm](https://img.shields.io/npm/v/@node-ts-cache/lru-storage.svg) | LRU cache with automatic eviction |
57+
| [@node-ts-cache/lru-redis-storage](./storages/lru-redis) | ![npm](https://img.shields.io/npm/v/@node-ts-cache/lru-redis-storage.svg) | Two-tier caching (local LRU + remote Redis) |
58+
| [@node-ts-cache/elasticsearch-storage](./storages/elasticsearch) | ![npm](https://img.shields.io/npm/v/@node-ts-cache/elasticsearch-storage.svg) | Elasticsearch storage for search-optimized caching |
59+
| [@node-ts-cache/memcached-storage](./storages/memcached) | ![npm](https://img.shields.io/npm/v/@node-ts-cache/memcached-storage.svg) | Memcached storage for distributed caching |
60+
| [@node-ts-cache/valkey-storage](./storages/valkey) | ![npm](https://img.shields.io/npm/v/@node-ts-cache/valkey-storage.svg) | Valkey storage (Redis-compatible, open source) |
5861

5962
## Documentation
6063

@@ -80,25 +83,28 @@ For detailed documentation, see the [main package README](./ts-cache/README.md).
8083
│ └───────┬────────┘ │
8184
├──────────────────────────┼──────────────────────────────────────┤
8285
│ ▼ │
83-
│ ┌──────────────────────────────────────────────────────────┐ │
84-
│ │ Storage Layer │ │
85-
│ ├──────────┬──────────┬──────────┬──────────┬─────────────┤ │
86-
│ │ Memory FS Redis LRU LRU+Redis │ │
87-
│ └──────────┴──────────┴──────────┴──────────┴─────────────┘ │
86+
│ ┌──────────────────────────────────────────────────────────────────────────────────┐ │
87+
│ │ Storage Layer │ │
88+
│ ├────────┬──────┬────────────┬──────────┬───────────────┬────────────┬──────────┤ │
89+
│ │ Memory │ FS Redis │ LRULRU+Redis │ Elasticsearch │ MemcachedValkey │ │
90+
│ └────────┴──────┴────────────┴──────────┴───────────────┴────────────┴──────────┘ │
8891
└─────────────────────────────────────────────────────────────────┘
8992
```
9093

9194
## Choosing a Storage
9295

93-
| Storage | Type | Use Case | Features |
94-
| ----------------------- | ----- | ---------------------------- | ----------------------------- |
95-
| **MemoryStorage** | Sync | Development, small datasets | Zero config, bundled |
96-
| **FsJsonStorage** | Async | Persistent local cache | File-based, survives restarts |
97-
| **NodeCacheStorage** | Sync | Production single-instance | TTL support, multi-ops |
98-
| **LRUStorage** | Sync | Memory-constrained apps | Auto-eviction, size limits |
99-
| **RedisStorage** | Async | Distributed systems | Shared cache, redis v4 |
100-
| **RedisIOStorage** | Async | Distributed systems | Compression, modern ioredis |
101-
| **LRUWithRedisStorage** | Async | High-performance distributed | Local + remote tiers |
96+
| Storage | Type | Use Case | Features |
97+
| ------------------------ | ----- | ---------------------------- | ------------------------------ |
98+
| **MemoryStorage** | Sync | Development, small datasets | Zero config, bundled |
99+
| **FsJsonStorage** | Async | Persistent local cache | File-based, survives restarts |
100+
| **NodeCacheStorage** | Sync | Production single-instance | TTL support, multi-ops |
101+
| **LRUStorage** | Sync | Memory-constrained apps | Auto-eviction, size limits |
102+
| **RedisStorage** | Async | Distributed systems | Shared cache, redis v4 |
103+
| **RedisIOStorage** | Async | Distributed systems | Compression, modern ioredis |
104+
| **LRUWithRedisStorage** | Async | High-performance distributed | Local + remote tiers |
105+
| **ElasticsearchStorage** | Async | Search-integrated caching | Full-text search, scalable |
106+
| **MemcachedStorage** | Async | High-performance distributed | Simple, fast, widely supported |
107+
| **ValkeyStorage** | Async | Distributed systems | Redis-compatible, open source |
102108

103109
## Requirements
104110

0 commit comments

Comments
 (0)