Skip to main content

Internal Caching

This is based on the Cache-Control headers returned by the API. If internal caching is enabled, objects will be cached automatically by the client until they are stale.

info

By default, internal caching is disabled.

Caching Duration
Some major routes and their `maxAge` values.
RouteValue
(seconds)
/clans/:clanTag120
/players/:playerTag60
/clans/:clanTag/warlog600
/clans/:clanTag/currentwar600
/clans/:clanTag/currentwar/leaguegroup600
/clanwarleagues/wars/:warTag600

Enable Caching

import { Client, CacheStore } from 'clashofclans.js';

const client = new Client({ cache: true, keys: ['***'] });
const client = new Client({
keys: ['***'],
cache: new CacheStore({ sweepInterval: 5 * 60 * 1000 })
});

Custom Store

Make your own adapter to cache or store the data in a persistent storage. Any store that follows Map API will work.

import { Client } from 'clashofclans.js';
import Keyv from 'keyv';

const client = new Client({
keys: ['***'],
cache: new Keyv('redis://user:pass@localhost:6379')
});
import { Client } from 'clashofclans.js';
import { CustomStore } from './custom-store';

const client = new Client({
keys: ['***'],
cache: new CustomStore()
});
Template
class Store<T> {
set(key: string, value: T, ttl?: number): boolean | Promise<boolean>;
get(key: string): T | null | Promise<T | null>;
delete(key: string): boolean | Promise<boolean>;
clear(): void | Promise<void>;
}