Skip to main content

Creating cache adapters

Implementing your custom ICacheAdapter​

In order to create an adapter you need to implement the ICacheAdapter contract.

Testing your custom ICacheAdapter​

We provide a complete test suite to test your cache adapter implementation. Simply use the cacheAdapterTestSuite function:

The suite provides preconfigured Vitest test cases with common edge case coverage and standardized cache adapter contract conformance testing.

Usage example:

./samples/cache-adapter-test-suite.ts
import { beforeEach, describe, expect, test } from "vitest";
import { cacheAdapterTestSuite } from "eridu-tech/cache/test-utilities";
import { MemoryCacheAdapter } from "eridu-tech/cache/memory-cache-adapter";

describe("class: MyCacheAdapter", () => {
cacheAdapterTestSuite({
createAdapter: () => new MemoryCacheAdapter(),
test,
beforeEach,
expect,
describe,
});
});

Implementing your custom ICache class​

In some cases, you may need to implement a custom Cache class to optimize performance for your specific technology stack. You can then directly implement the ICache contract.

Testing your custom ICache class​

We provide a complete test suite to verify your custom cache class implementation. Simply use the cacheTestSuite function:

The suite provides preconfigured Vitest test cases with common edge case coverage and standardized cache contract conformance testing.

Usage example:

./samples/cache-test-suite.ts
import { beforeEach, describe, expect, test } from "vitest";
import { cacheTestSuite } from "eridu-tech/cache/test-utilities";
import { Cache } from "eridu-tech/cache";
import { MemoryCacheAdapter } from "eridu-tech/cache/memory-cache-adapter";

describe("class: MyCache", () => {
cacheTestSuite({
createCache: () =>
new Cache({
adapter: new MemoryCacheAdapter(),
}),
test,
beforeEach,
expect,
describe,
});
});

Further information​

For further information refer to eridu-tech/cache API docs.