Weblutions Documentation
Weblutions Main Site Contact Us Our Discord
Some pages are still pending proper formatting, if required refer to the legacy documentation website.
FaxStore IconFaxStore

Weblutions Documentation / FaxStore / Global Cache

Updated

Global Cache

By Josh M. 2 mins 7

FaxStore offers a built in global cache which can accessed in any FaxStore file and is primarily used to fetch data that does't require database queries. This is useful to developers and extension creators as data is cached and automatically refreshed. This can reduce non urgent queries and API calls that may not be needed.

FaxStore caches a range of items currently including; products, reviews, customers, settings, and more! By using the global variable CACHE the object can be referred to and used in a read only state. The cache automatically updates every hour, or on specific calls, like when a product is created, edited, or deleted the product cache is updated, same with other alike items.

The FaxStore cache is only available in versions 3.0.0 and above.

Cached Content

  • CACHE.customers contains an array of customer data.
    Not all database data is placed into the cache but the most common data is.

  • CACHE.reviews contains an array of all reviews.

  • CACHE.products contains an array of product data
    Not all database data is placed into the cache but the most common data is.

  • CACHE.settings contains an object of all site settings from the database.

  • CACHE.categories contains an array of all store categories.

  • CACHE.discord contains an object of the Discord bot, this can be used to access channels, create commands and use the Discord integration.

  • CACHE.counts contains a count collection of many tables within the store, used for analytics


Code Usage & Example

To access the cache in an extension or other code file in FaxStore, the CACHE variable can be referred to. See the below examples of certain use cases. The cache should be treated as read only and never be written to as it will be cleared on refresh.

console.log(CACHE.customers)
// Outputs all customers

let joshs = CACHE.customers.find(f => f.username.includes('josh'));
console.log(joshs)
// Outputs all customers wit "josh" within their name

let user = CACHE.customers.find(f => f.id === '9029489594923949234');
console.log(user)
// Outputs any user with the ID 9029489594923949234

The same type of process can be done for any other of the cached content.