@chidchanun/bcp 0.2.15 → 0.2.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # BCP Framework
2
2
 
3
- BCP Framework is a React full-stack framework for file-based routing, SSR, SPA navigation, server data loading, API routes, authentication, authorization, SQL databases, background jobs, scheduling, workflow orchestration, transactional events, realtime delivery, framework-native testing, plugin/module composition, observability, uploads, storage and standalone Node.js deployment.
3
+ BCP Framework is a React full-stack framework for file-based routing, SSR, SPA navigation, server data loading, API routes, authentication, authorization, SQL databases, background jobs, scheduling, workflow orchestration, transactional events, realtime delivery, framework-native testing, plugin/module composition, distributed caching, observability, uploads, storage and standalone Node.js deployment.
4
4
 
5
- > **Development target:** `0.2.15Plugin & Module Platform`
5
+ > **Development target:** `0.2.16Cache Platform v2`
6
6
  >
7
- > `0.2.15` remains unreleased until local validation, RC checks, tagging and npm publication complete.
7
+ > `0.2.16` remains unreleased until local validation, RC checks, tagging and npm publication complete.
8
8
 
9
9
  ## Current platform
10
10
 
@@ -27,9 +27,9 @@ BCP Framework is a React full-stack framework for file-based routing, SSR, SPA n
27
27
  | Realtime | Channels/rooms, presence, broker delivery, WebSocket adapter contract, SSE and heartbeat |
28
28
  | Testing | Request/route/page/auth/database/middleware/jobs/workflow/outbox/realtime/SSE test harnesses |
29
29
  | Plugins & modules | Dependency ordering, lifecycle hooks, config parsing, service registry and async extension hooks |
30
+ | Caching | Legacy request/data cache plus Cache Platform v2 adapters, Redis-compatible cache/locks, stampede protection, TTL/tag/path invalidation and metrics |
30
31
  | Observability | Structured logs, metrics, Prometheus output and health/readiness checks |
31
32
  | Uploads & storage | Multipart streaming, Local/S3-compatible storage and signed URLs |
32
- | Caching | Response cache and revalidation primitives |
33
33
  | Configuration | Typed config/environment validation and diagnostics |
34
34
  | Production | Standalone Node.js build, packaging, dependency pruning, Docker starter and graceful shutdown |
35
35
  | Documentation | Manifest-driven docs, platform metadata and API reference |
@@ -69,6 +69,7 @@ Generated projects normally use one framework dependency:
69
69
  ## Core backend entrypoints
70
70
 
71
71
  ```ts
72
+ import { createCacheStore } from "bcp/cache";
72
73
  import { db } from "bcp/database";
73
74
  import { createAuth } from "bcp/auth";
74
75
  import { createJobQueue } from "bcp/jobs";
@@ -446,6 +447,100 @@ If startup fails, already-started plugins are stopped in reverse order before th
446
447
 
447
448
  Read more: [Plugin & Module Platform](docs/plugin-module-platform.md)
448
449
 
450
+ ## Cache Platform v2 — 0.2.16
451
+
452
+ `0.2.16` keeps the original `cache()` and `dedupe()` APIs while adding provider-neutral asynchronous cache stores for production multi-instance applications.
453
+
454
+ Create a cache store:
455
+
456
+ ```ts
457
+ import {
458
+ createCacheStore,
459
+ } from "bcp/cache";
460
+
461
+ export const applicationCache =
462
+ createCacheStore();
463
+ ```
464
+
465
+ Cache-aside loading:
466
+
467
+ ```ts
468
+ const user =
469
+ await applicationCache.getOrSet(
470
+ "user:42",
471
+ async () =>
472
+ loadUser(42),
473
+ {
474
+ ttlMs: 60_000,
475
+ tags: [
476
+ "users",
477
+ ],
478
+ paths: [
479
+ "/users/42",
480
+ ],
481
+ }
482
+ );
483
+ ```
484
+
485
+ Within one store, concurrent misses share one loader automatically.
486
+
487
+ For multiple application instances, use shared cache and lock adapters:
488
+
489
+ ```ts
490
+ import {
491
+ createRedisCacheAdapter,
492
+ createRedisCacheLockAdapter,
493
+ } from "bcp/cache";
494
+
495
+ const redisCache =
496
+ createRedisCacheAdapter({
497
+ client: redisClient,
498
+ });
499
+
500
+ const redisLock =
501
+ createRedisCacheLockAdapter({
502
+ client: redisClient,
503
+ });
504
+
505
+ export const cache =
506
+ createCacheStore({
507
+ adapter: redisCache,
508
+ lock: redisLock,
509
+ });
510
+ ```
511
+
512
+ The default Redis namespace is `bcp:{cache}`. BCP does not install or own a Redis library/connection.
513
+
514
+ Distributed `getOrSet()` uses owner-scoped lock leases, heartbeat renewal when supported, double-check-after-lock, contention wait/poll and configurable lock-timeout behavior.
515
+
516
+ Tag/path invalidation remains available through the new async store:
517
+
518
+ ```ts
519
+ await cache.revalidateTag(
520
+ "users"
521
+ );
522
+
523
+ await cache.revalidatePath(
524
+ "/dashboard"
525
+ );
526
+ ```
527
+
528
+ Connect cache events to BCP metrics:
529
+
530
+ ```ts
531
+ const cache =
532
+ createCacheStore({
533
+ metrics:
534
+ createCacheMetrics(
535
+ metricsRegistry
536
+ ),
537
+ });
538
+ ```
539
+
540
+ Prepared npm packages compile `bcp/cache` to `cache.mjs` for standalone Node runtime use.
541
+
542
+ Read more: [Cache Platform v2](docs/cache-platform-v2.md)
543
+
449
544
  ## Public entrypoints
450
545
 
451
546
  ```text
@@ -518,10 +613,13 @@ Browser / API / Realtime clients
518
613
  outbox jobs |
519
614
  \__________|_________/
520
615
  durable state
521
-
522
- Testing Platform exercises these server contracts without becoming part of browser runtime.
616
+ |
617
+ shared cache layer
618
+ Redis / other
523
619
  ```
524
620
 
621
+ Cache is an optimization layer and must not replace durable application truth or transactional invariants.
622
+
525
623
  ## Packaging
526
624
 
527
625
  ```bash
@@ -547,7 +645,7 @@ docs/api-manifest.json
547
645
 
548
646
  ## Release validation
549
647
 
550
- Before publishing `0.2.15`:
648
+ Before publishing `0.2.16`:
551
649
 
552
650
  ```bash
553
651
  npm run typecheck
@@ -558,7 +656,7 @@ npm run test:package
558
656
  npm run rc:check
559
657
  ```
560
658
 
561
- `0.2.15` adds unit and prepared-package smoke coverage for plugin dependency ordering, missing/cyclic dependencies, modules, config parsing, shared services, async hooks, lifecycle rollback, compiled `plugins.mjs` execution and browser boundary enforcement.
659
+ `0.2.16` adds unit and prepared-package smoke coverage for TTL/tag/path invalidation, local singleflight, distributed lock contention, lock timeout behavior, Redis cache/lock command contracts, cache metrics and compiled `cache.mjs` execution.
562
660
 
563
661
  Do not tag or publish until the exact final release commit passes the full RC sequence.
564
662
 
@@ -588,12 +686,13 @@ Do not tag or publish until the exact final release commit passes the full RC se
588
686
  | `0.2.13` | Realtime Platform |
589
687
  | `0.2.14` | Testing Platform |
590
688
  | `0.2.15` | Plugin & Module Platform |
689
+ | `0.2.16` | Cache Platform v2 |
591
690
 
592
691
  ## Roadmap
593
692
 
594
- `0.2.15` establishes reusable server-side extension composition while keeping BCP subsystem contracts provider-neutral and independently testable.
693
+ `0.2.16` establishes provider-neutral shared caching and distributed cache-fill coordination while preserving the original process-local cache API.
595
694
 
596
- The next logical milestone is **`0.2.16Cache Platform v2`**, focused on distributed cache adapters, Redis-compatible caching, locking, stampede protection and production cache observability.
695
+ The next logical milestone is **`0.2.17Observability Platform v3`**, focused on tracing, correlation across HTTP/jobs/workflows/events/realtime/cache, richer runtime metrics and exporter/provider integration.
597
696
 
598
697
  Native desktop/mobile compilation remains later roadmap work.
599
698
 
package/docs/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  The `docs/` directory is the documentation source of truth for BCP Framework and is organized for **`bcp-docs-web`**.
4
4
 
5
- > **Documentation target:** BCP Framework `0.2.15Plugin & Module Platform`
5
+ > **Documentation target:** BCP Framework `0.2.16Cache Platform v2`
6
6
  >
7
7
  > **Release state:** unreleased development target until RC validation, tagging and npm publication complete.
8
8
 
@@ -41,55 +41,61 @@ Framework source and tests remain authoritative for runtime behavior.
41
41
  | `0.2.13` | Realtime Platform |
42
42
  | `0.2.14` | Testing Platform |
43
43
  | `0.2.15` | Plugin & Module Platform |
44
+ | `0.2.16` | Cache Platform v2 |
44
45
 
45
- ## 0.2.15Plugin & Module Platform
46
+ ## 0.2.16Cache Platform v2
46
47
 
47
- `0.2.15` adds the server-only `bcp/plugins` public entrypoint.
48
+ `0.2.16` extends the existing `bcp/cache` public entrypoint while keeping its original process-local APIs backward compatible.
48
49
 
49
- Primary APIs:
50
+ Primary Cache Store v2 APIs:
50
51
 
51
52
  ```ts
52
53
  import {
53
- createPluginHookBus,
54
- createPluginHost,
55
- createPluginServiceRegistry,
56
- defineModule,
57
- definePlugin,
58
- } from "bcp/plugins";
54
+ createCacheMetrics,
55
+ createCacheStore,
56
+ createMemoryCacheAdapter,
57
+ createMemoryCacheLockAdapter,
58
+ createRedisCacheAdapter,
59
+ createRedisCacheLockAdapter,
60
+ } from "bcp/cache";
59
61
  ```
60
62
 
61
63
  Runtime model:
62
64
 
63
65
  ```text
64
- Plugin Host
65
- |
66
- +-- dependency graph
67
- | -> required / optional dependencies
68
- |
69
- +-- lifecycle
70
- | -> setup -> start -> stop -> dispose
71
- |
72
- +-- service registry
73
- | -> typed shared application services
74
- |
75
- +-- async hook bus
76
- -> in-process extension points
66
+ Application
67
+ |
68
+ v
69
+ CacheStore
70
+ |
71
+ +-- CacheAdapter
72
+ | +-- memory
73
+ | +-- Redis-compatible
74
+ |
75
+ +-- CacheLockAdapter
76
+ | +-- memory
77
+ | +-- Redis-compatible
78
+ |
79
+ +-- local singleflight
80
+ +-- distributed cache-fill lease
81
+ +-- TTL / tags / paths
82
+ +-- metrics sink
77
83
  ```
78
84
 
79
- Startup follows topological dependency order. Stop/dispose runs in reverse order. A failed startup rolls back plugins that already started.
85
+ `getOrSet()` deduplicates cache fills inside one process. With a shared lock adapter, multiple processes coordinate cache misses through owner-scoped leases, optional lock renewal and wait/poll behavior.
80
86
 
81
- Modules are named bundles of plugins; they do not create a separate lifecycle graph.
87
+ The Redis reference adapter uses the default hash-tagged namespace `bcp:{cache}` and does not install or own a Redis client.
82
88
 
83
89
  New/updated sources:
84
90
 
85
91
  | Source | Purpose |
86
92
  | --- | --- |
87
- | `plugin-module-platform.md` | Plugin definitions, modules, dependency order, lifecycle, config, services and hooks |
88
- | `api-reference.md` | `bcp/plugins` public APIs |
89
- | `platform-manifest.json` | Plugin capability flags and public entrypoint |
90
- | `api-manifest.json` | `bcp/plugins` source/guide ownership |
91
- | `docs-web-manifest.json` | Plugin docs navigation and `0.2.15` release route |
92
- | `releases/0.2.15.md` | Plugin & Module Platform release notes |
93
+ | `cache-platform-v2.md` | Adapter contracts, Redis cache/locks, stampede protection, TTL/invalidation and metrics |
94
+ | `api-reference.md` | `bcp/cache` Cache Platform v2 APIs |
95
+ | `platform-manifest.json` | Cache v2 capability flags |
96
+ | `api-manifest.json` | Updated `bcp/cache` source/guide ownership |
97
+ | `docs-web-manifest.json` | Cache v2 docs navigation and `0.2.16` release route |
98
+ | `releases/0.2.16.md` | Cache Platform v2 release notes |
93
99
 
94
100
  ## Update rule
95
101
 
@@ -117,8 +123,9 @@ When framework behavior or public surface changes:
117
123
  | `/docs/realtime-platform` | `realtime-platform.md` |
118
124
  | `/docs/testing-platform` | `testing-platform.md` |
119
125
  | `/docs/plugin-module-platform` | `plugin-module-platform.md` |
126
+ | `/docs/cache-platform-v2` | `cache-platform-v2.md` |
120
127
  | `/docs/api-reference` | `api-reference.md` |
121
- | `/releases/0.2.15` | `releases/0.2.15.md` |
128
+ | `/releases/0.2.16` | `releases/0.2.16.md` |
122
129
 
123
130
  Every route/source pair is validated by unit tests.
124
131
 
@@ -149,7 +156,7 @@ The API-manifest entrypoint set must match the platform public-entrypoint set ex
149
156
 
150
157
  ## Release validation
151
158
 
152
- Before publishing `0.2.15`:
159
+ Before publishing `0.2.16`:
153
160
 
154
161
  ```bash
155
162
  npm run typecheck
@@ -160,6 +167,6 @@ npm run test:package
160
167
  npm run rc:check
161
168
  ```
162
169
 
163
- Plugin Platform validation covers dependency ordering, missing/cyclic dependencies, module composition, typed config parsing, service sharing, async hooks, reverse shutdown, startup rollback, server-only boundaries, compiled `plugins.mjs` package execution and docs/platform/API parity.
170
+ Cache Platform v2 validation covers TTL/tag/path invalidation, local singleflight, cross-store distributed locking, lock timeout behavior, Redis command contracts, metrics integration, compiled `cache.mjs` package execution and docs/platform/API parity.
164
171
 
165
172
  The final release tag must point to the exact commit that passed the complete RC sequence.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
3
  "framework": "bcp",
4
- "version": "0.2.15",
4
+ "version": "0.2.16",
5
5
  "releaseState": "unreleased",
6
6
  "coverage": "public-entrypoints",
7
7
  "entrypoints": [
@@ -26,8 +26,8 @@
26
26
  "source": "packages/client/src/cache.ts",
27
27
  "environment": "server-preferred",
28
28
  "route": "/docs/api-reference#bcp-cache",
29
- "summary": "Cache, deduplication, statistics and path/tag revalidation primitives.",
30
- "guides": ["/docs/caching"]
29
+ "summary": "Backward-compatible request/data caching plus Cache Platform v2 adapters, Redis-compatible distributed cache and locks, stampede protection, TTL/tag/path invalidation and metrics integration.",
30
+ "guides": ["/docs/caching", "/docs/cache-platform-v2", "/docs/observability"]
31
31
  },
32
32
  {
33
33
  "package": "bcp/config",
@@ -123,7 +123,7 @@
123
123
  "environment": "server",
124
124
  "route": "/docs/api-reference#bcp-observability",
125
125
  "summary": "In-process metrics, Prometheus exposition, request metrics middleware and health/readiness checks.",
126
- "guides": ["/docs/observability", "/docs/development-logging"]
126
+ "guides": ["/docs/observability", "/docs/development-logging", "/docs/cache-platform-v2"]
127
127
  },
128
128
  {
129
129
  "package": "bcp/server",
@@ -26,9 +26,66 @@ Related guide: [Hydration](hydration.md).
26
26
 
27
27
  ## `bcp/cache`
28
28
 
29
- Caching, deduplication, statistics and path/tag revalidation primitives.
29
+ Caching APIs include the original process-local request/data cache plus Cache Platform v2 provider contracts for shared production caches.
30
30
 
31
- Related guide: [Caching](caching.md).
31
+ Legacy-compatible exports remain:
32
+
33
+ ```ts
34
+ import {
35
+ cache,
36
+ clearCache,
37
+ dedupe,
38
+ getCacheStats,
39
+ revalidatePath,
40
+ revalidateTag,
41
+ } from "bcp/cache";
42
+ ```
43
+
44
+ Cache Platform v2 adds:
45
+
46
+ ```ts
47
+ import {
48
+ createCacheMetrics,
49
+ createCacheStore,
50
+ createMemoryCacheAdapter,
51
+ createMemoryCacheLockAdapter,
52
+ createRedisCacheAdapter,
53
+ createRedisCacheLockAdapter,
54
+ type CacheAdapter,
55
+ type CacheAdapterEntry,
56
+ type CacheAdapterSetOptions,
57
+ type CacheGetOrSetOptions,
58
+ type CacheLockAdapter,
59
+ type CacheMetricsRegistryLike,
60
+ type CacheMetricsSink,
61
+ type CacheStore,
62
+ type CacheStoreEvent,
63
+ type CacheStoreOptions,
64
+ type CacheStoreSetOptions,
65
+ type CacheStoreStats,
66
+ type MemoryCacheAdapter,
67
+ type MemoryCacheLockAdapter,
68
+ type RedisCacheAdapter,
69
+ type RedisCacheAdapterOptions,
70
+ type RedisCacheCommandClient,
71
+ type RedisCacheLockAdapter,
72
+ type RedisCacheLockAdapterOptions,
73
+ } from "bcp/cache";
74
+ ```
75
+
76
+ `createCacheStore()` exposes async `get()`, `set()`, `delete()`, `clear()`, `revalidateTag()`, `revalidatePath()`, `getOrSet()`, `stats()` and `close()` operations.
77
+
78
+ `getOrSet()` always provides local singleflight deduplication. When a `CacheLockAdapter` is supplied, cache fills can also coordinate across multiple application instances with owner-scoped leases, optional renewal and configurable contention timeout behavior.
79
+
80
+ `createRedisCacheAdapter()` and `createRedisCacheLockAdapter()` use a minimal `sendCommand()` client contract. BCP does not install or own a Redis library/connection. The default namespace is `bcp:{cache}` for Redis Cluster hash-slot locality.
81
+
82
+ Cache Store v2 uses millisecond TTL (`ttlMs`), while the original `cache()` API keeps its existing `revalidate`-seconds contract.
83
+
84
+ `createCacheMetrics()` adapts cache events to the existing BCP `MetricsRegistry` shape without coupling the cache package directly to a specific exporter.
85
+
86
+ Prepared npm packages compile the runtime entrypoint to `packages/client/src/cache.mjs`.
87
+
88
+ Related guides: [Caching](caching.md), [Cache Platform v2](cache-platform-v2.md), [Observability Platform v2](observability.md).
32
89
 
33
90
  ## `bcp/config`
34
91
 
@@ -358,7 +415,9 @@ Related guides: [Plugin & Module Platform](plugin-module-platform.md), [Configur
358
415
 
359
416
  Server-only Observability Platform v2 APIs for process-local counters, gauges, histograms, Prometheus exposition, request metrics middleware and health/readiness checks.
360
417
 
361
- Related guides: [Observability Platform v2](observability.md), [Logging](development-logging.md).
418
+ `Cache Platform v2` can connect to this registry through `createCacheMetrics()` from `bcp/cache`.
419
+
420
+ Related guides: [Observability Platform v2](observability.md), [Logging](development-logging.md), [Cache Platform v2](cache-platform-v2.md).
362
421
 
363
422
  ## `bcp/server`
364
423