Skip to main content

CacheManager

Purpose

The CacheManager class is used for storing and retrieving specific values from the client-side browser cache, using the localstorage-slim library.

Methods

getCacheEntry
// Retrieves an entry from the user's browser cache.
// If an entry is not a manual entry, then if the browser cache
// does not have the value, it is fetched via AJAX (hence the async).
static async getCacheEntry(entry, formData = null);

// Example usage
CacheManager.getCacheEntry(CacheManager.cVars.searchTagsList);

This method behaves differently depending on whether the value being retrieved is from the cVars or cManualVars objects, explained below.

Variables: cVars and cManualVars

cVars

Each cVar is an object with an lsKey, ajaxUrl, and ttl field. An example is below:

searchTagsList: {
  lsKey: "deserted-chateau-search-tags-list",
  ajaxUrl: "/forms/search/GetTopTags",
  ttl: 60 * 60 * 24,
},

This tells the CacheManager which key the value is stored in within the browser cache, how long the cached value should remain valid for, and the AJAX form to use to retrieve a new copy of the value if needed.

cManualVars

These are similar to cVars, but have no ajaxUrl value; they must be populated manually, and most of these keys do not have an expiry ttl or have it set to null (do not expire).