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:

  • Preconfigured Vitest test cases
  • Common edge case coverage

Usage example:

// filename: MyCacheAdapter.test.ts

import { beforeEach, describe, expect, test } from "vitest";
import { cacheAdapterTestSuite } from "eridu-tech/cache/test-utilities";
import { MemoryCacheAdapter } from "./MemoryCacheAdapter.js";

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:

  • Preconfigured Vitest test cases
  • Standardized cache behavior validation
  • Common edge case coverage

Usage example:

// filename: MyCache.test.ts

import { beforeEach, describe, expect, test } from "vitest";
import { cacheTestSuite } from "eridu-tech/cache/test-utilities";
import { MyCache } from "./MyCache.js";

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

Further information

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