Skip to content

Commit 11100fc

Browse files
committed
feat: remove clearClientSnapshots
1 parent a23ddb1 commit 11100fc

7 files changed

Lines changed: 16 additions & 42 deletions

File tree

packages/next/README.md

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export function ThemeToggle() {
6363

6464
### Pages Router
6565

66-
**1. Set up ReplaneProvider in _app.tsx:**
66+
**1. Set up ReplaneProvider in \_app.tsx:**
6767

6868
```tsx
6969
// pages/_app.tsx
@@ -258,30 +258,11 @@ Fetches a snapshot of all configs. Use in `getServerSideProps`, `getStaticProps`
258258
const snapshot = await getReplaneSnapshot<AppConfigs>({
259259
baseUrl: process.env.REPLANE_BASE_URL!,
260260
sdkKey: process.env.REPLANE_SDK_KEY!,
261-
cacheTtlMs: 60_000, // optional, default 60 seconds
261+
// by default, getReplaneSnapshot will reuse the created client for 60 seconds for fast subsequent calls, the client will be syncing with the server in the background during this time
262+
keepAliveMs: 60_000,
262263
});
263264
```
264265

265-
#### `clearSnapshotCache(): Promise<void>`
266-
267-
Clears the internal client cache. Useful for testing.
268-
269-
```tsx
270-
await clearSnapshotCache();
271-
```
272-
273-
## Environment Variables
274-
275-
```env
276-
# Server-side only (for SSR/SSG)
277-
REPLANE_BASE_URL=https://api.replane.io
278-
REPLANE_SDK_KEY=your-sdk-key
279-
280-
# Client-side (for live updates)
281-
NEXT_PUBLIC_REPLANE_BASE_URL=https://api.replane.io
282-
NEXT_PUBLIC_REPLANE_SDK_KEY=your-sdk-key
283-
```
284-
285266
## Examples
286267

287268
See the [examples](./examples) directory for complete working examples:

packages/next/src/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ export {
8686
createReplaneHook,
8787
createConfigHook,
8888
clearSuspenseCache,
89-
clearSnapshotCache,
9089
} from "@replanejs/react";
9190

9291
export type {

packages/react/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ export type {
88
} from "./types";
99

1010
// Re-export snapshot utilities from SDK
11-
export { getReplaneSnapshot, clearSnapshotCache } from "@replanejs/sdk";
11+
export { getReplaneSnapshot } from "@replanejs/sdk";
1212
export type { GetReplaneSnapshotOptions } from "@replanejs/sdk";

packages/sdk/src/index.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
// Re-export public API
22

33
// Client functions
4-
export {
5-
createReplaneClient,
6-
createInMemoryReplaneClient,
7-
restoreReplaneClient,
8-
} from "./client";
4+
export { createReplaneClient, createInMemoryReplaneClient, restoreReplaneClient } from "./client";
95

106
// Error types
117
export { ReplaneError, ReplaneErrorCode } from "./error";
@@ -22,5 +18,5 @@ export type {
2218
} from "./client-types";
2319

2420
// Snapshot utilities
25-
export { getReplaneSnapshot, clearSnapshotCache } from "./snapshot";
21+
export { getReplaneSnapshot } from "./snapshot";
2622
export type { GetReplaneSnapshotOptions } from "./snapshot";

packages/sdk/src/snapshot.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export interface GetReplaneSnapshotOptions<T extends object> extends ReplaneClie
1010
* for instant subsequent calls within this duration.
1111
* @default 60_000 (1 minute)
1212
*/
13-
cacheTtlMs?: number;
13+
keepAliveMs?: number;
1414
}
1515

1616
interface CachedClient {
@@ -27,10 +27,10 @@ function getCacheKey<T extends object>(options: ReplaneClientOptions<T>): string
2727

2828
type TimeoutId = ReturnType<typeof setTimeout>;
2929

30-
function setupCleanupTimeout(cacheKey: string, cacheTtlMs: number): TimeoutId {
30+
function setupCleanupTimeout(cacheKey: string, keepAliveMs: number): TimeoutId {
3131
return setTimeout(() => {
3232
clientCache.delete(cacheKey);
33-
}, cacheTtlMs);
33+
}, keepAliveMs);
3434
}
3535

3636
/**
@@ -49,15 +49,15 @@ function setupCleanupTimeout(cacheKey: string, cacheTtlMs: number): TimeoutId {
4949
export async function getReplaneSnapshot<T extends object>(
5050
options: GetReplaneSnapshotOptions<T>
5151
): Promise<ReplaneSnapshot<T>> {
52-
const { cacheTtlMs = 60_000, ...clientOptions } = options;
52+
const { keepAliveMs = 60_000, ...clientOptions } = options;
5353

5454
const cacheKey = getCacheKey(clientOptions);
5555
const cached = clientCache.get(cacheKey);
5656

5757
// Return from cache if valid
5858
if (cached) {
5959
clearTimeout(cached.timeoutId);
60-
cached.timeoutId = setupCleanupTimeout(cacheKey, cacheTtlMs);
60+
cached.timeoutId = setupCleanupTimeout(cacheKey, keepAliveMs);
6161

6262
const client = await cached.clientPromise;
6363
return client.getSnapshot() as ReplaneSnapshot<T>;
@@ -67,7 +67,7 @@ export async function getReplaneSnapshot<T extends object>(
6767
const clientPromise = createReplaneClient<T>(clientOptions);
6868
const entry: CachedClient = {
6969
clientPromise: clientPromise,
70-
timeoutId: setupCleanupTimeout(cacheKey, cacheTtlMs),
70+
timeoutId: setupCleanupTimeout(cacheKey, keepAliveMs),
7171
};
7272
clientCache.set(cacheKey, entry);
7373

packages/sdk/tests/snapshot.spec.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,10 @@ describe("getReplaneSnapshot", () => {
157157
});
158158

159159
it("should expire cache after TTL", async () => {
160-
const cacheTtlMs = 100; // Use short TTL for test
160+
const keepAliveMs = 100; // Use short TTL for test
161161

162162
// First call
163-
const snapshot1Promise = getSnapshot({ cacheTtlMs });
163+
const snapshot1Promise = getSnapshot({ keepAliveMs });
164164
const connection1 = await mockServer.acceptConnection();
165165
await connection1.push({
166166
type: "init",
@@ -170,10 +170,10 @@ describe("getReplaneSnapshot", () => {
170170
await sync();
171171

172172
// Wait for TTL to expire
173-
await delay(cacheTtlMs + 50);
173+
await delay(keepAliveMs + 50);
174174

175175
// Second call - should create new client since cache expired
176-
const snapshot2Promise = getSnapshot({ cacheTtlMs });
176+
const snapshot2Promise = getSnapshot({ keepAliveMs });
177177
const connection2 = await mockServer.acceptConnection();
178178
await connection2.push({
179179
type: "init",
@@ -184,7 +184,6 @@ describe("getReplaneSnapshot", () => {
184184

185185
expect(snapshot2.configs[0].value).toBe("value2");
186186
});
187-
188187
});
189188

190189
describe("clearSnapshotCache", () => {

packages/svelte/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ export {
1313
createInMemoryReplaneClient,
1414
restoreReplaneClient,
1515
getReplaneSnapshot,
16-
clearSnapshotCache,
1716
ReplaneError,
1817
ReplaneErrorCode,
1918
} from "@replanejs/sdk";

0 commit comments

Comments
 (0)