Skip to content

Commit 2fbe9eb

Browse files
committed
add cache and refresh strategies
1 parent dc2e2c6 commit 2fbe9eb

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,29 @@ growthBook.isOn("featureKey");
131131
```
132132

133133
## Usage
134+
## Caching & Refresh Strategy
135+
136+
### Cache modes
137+
138+
The SDK supports multiple cache modes for persisting feature payloads:
139+
140+
- FILE: persist to a writable directory (configurable). Defaults to a safe OS-specific cache dir (or `java.io.tmpdir`).
141+
- MEMORY: in-process cache only (no filesystem writes).
142+
- NONE: no cache I/O. Runtime still holds the latest fetched features.
143+
- CUSTOM: supply your own `GbCacheManager` implementation.
144+
145+
You can configure these through `Options` when using `GrowthBookClient`, or via the repository builder’s `cacheManager` directly. When cache is disabled (`isCacheDisabled=true`), the repository won’t attempt any persistence.
146+
147+
### STALE_WHILE_REVALIDATE (default)
148+
149+
With the SWR strategy, the repository will:
150+
151+
- Perform an initial synchronous fetch during `initialize()`.
152+
- Start a lightweight background poller that revalidates features on a fixed delay (by default equal to the TTL). The poller is protected against overlapping runs and logs start/end of each polling cycle.
153+
- Keep the latest features in memory and invoke registered `FeatureRefreshCallback`s when updated so the `GlobalContext` stays fresh.
154+
155+
For SSE connections, the repository establishes a server‑sent events stream and updates as changes arrive; the SWR poller is not used.
156+
134157

135158
- The `evalFeature()` method evaluates a feature based on the provided parameters.
136159
It takes three arguments: a string representing the unique identifier of the feature,

lib/src/main/resources/FEATURE_CACHE.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)