Skip to content

Commit 7d73dd0

Browse files
committed
updating legacy load
1 parent 4ae88d2 commit 7d73dd0

File tree

5 files changed

+30
-3
lines changed

5 files changed

+30
-3
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[["1","2","3"],{"key":"4","value":"5"},{"key":"6","value":"7","expires":1759890350988},{"key":"7","value":"8","expires":1759890351238},"baz",[1,2,3],"foo","bar",{"foo":"7"}]

packages/flat-cache/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ export class FlatCache extends Hookified {
187187
if (Array.isArray(items)) {
188188
for (const item of items) {
189189
if (item && typeof item === "object" && "key" in item) {
190-
this._cache.set(item.key, item.value);
190+
this._cache.set(item.key, item.value, item.expires);
191191
}
192192
}
193193
} else {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[["1","2","3"],{"key":"4","value":"5"},{"key":"6","value":"7","expires":1759881587731},{"key":"7","value":"8","expires":1759881587981},"baz",[1,2,3],"foo","bar",{"foo":"7"}]

packages/flat-cache/test/index.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ describe("flat-cache load from persisted cache", () => {
205205
});
206206

207207
test("should load the cache from the file with expiration", async () => {
208-
const cacheDir = ".cachefoo3";
208+
const cacheDir = ".cachefoo456";
209209
const cacheId = "cache4";
210210
const firstCache = new FlatCache({ cacheDir, cacheId });
211211
firstCache.setKey("foo", "bar", 250);
@@ -223,7 +223,7 @@ describe("flat-cache load from persisted cache", () => {
223223
expect(secondCache.getKey("baz")).toEqual([1, 2, 3]);
224224
await sleep(300);
225225
expect(secondCache.getKey("bar")).toBeUndefined();
226-
firstCache.destroy(true);
226+
//firstCache.destroy(true);
227227
});
228228

229229
test("should load cache via file stream", async () => {

packages/flat-cache/test/legacy.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,29 @@ describe("Legacy Store", () => {
2828
expect(value).toBeDefined();
2929
expect(value).toHaveProperty("data", "test data");
3030
});
31+
32+
test("Load cache4 legacy format via FlatCache", () => {
33+
const cache = new FlatCache();
34+
const cache4Path = path.resolve(__dirname, "fixtures/.cache/cache4");
35+
36+
cache.loadFile(cache4Path);
37+
38+
// Verify the data was loaded correctly from cache4
39+
// The file contains: baz, foo, bar
40+
const valueBaz = cache.getKey("baz");
41+
expect(valueBaz).toEqual([1, 2, 3]);
42+
43+
const valueFoo = cache.getKey("foo");
44+
expect(valueFoo).toBe("bar");
45+
46+
const valueBar = cache.getKey("bar");
47+
expect(valueBar).toEqual({ foo: "bar" });
48+
49+
// Check that all keys are present
50+
const keys = cache.keys();
51+
expect(keys).toContain("baz");
52+
expect(keys).toContain("foo");
53+
expect(keys).toContain("bar");
54+
expect(keys.length).toBe(3);
55+
});
3156
});

0 commit comments

Comments
 (0)