> Portal Navigation: > > - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version. > - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages). > - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`). > - Top-level index of all portals: https://dev.wix.com/docs/llms.txt > - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt # Method name: invalidateCache(invalidationMethods: Array, options: InvalidateCacheOptions) # Method package: wixCacheBackend # Method menu location: wixCacheBackend --> cache --> invalidateCache # Method Link: https://dev.wix.com/docs/velo/apis/wix-cache-backend/cache/invalidate-cache.md # Method Description: >**Note:** This API is only supported when developing a site. Invalidates or clears previously cached return values based on specified tags. The `invalidationMethods` parameter accepts an array of objects, each containing a `tag` field. These tags are defined when caching return values of web methods ([Velo](https://dev.wix.com/docs/velo/api-reference/wix-web-module/web-method.md) | [SDK](https://dev.wix.com/docs/sdk/core-modules/web-methods/web-method.md)), and for routers (currently [Velo](https://dev.wix.com/docs/velo/api-reference/wix-router/ok.md) only). For example, an array such as `[{ tag: "contacts" }, { tag: "labels" }]` will clear any cached return values tagged with "contacts" or "labels." Any cache containing at least one tag specified in the `invalidationMethods` parameter will be cleared.
__Important:__ - If you don't specify any tags in the `invalidationsMethod` parameter, no caches are invalidated. - If you don't call Invalidate Cache, caches are only invalidated when the Time to Live (TTL) expires or when the site is republished with a code change. - (Velo only) Call Invalidate Cache to invalidate your web method and router caches. To invalidate Server Side Rendering (SSR) caches for your site, use the `invalidateCache()` function from the [`wix-site-backend`](https://dev.wix.com/docs/velo/api-reference/wix-site-backend/invalidate-cache.md) module.
# Method Code Examples: *** Note: do not assume any prop names or enum values other than the ones in the example. ## Cache the value returned from a function, then invalidate it ```javascript import { cache } from "wix-cache-backend"; import { webMethod, Permissions } from "wix-web-module"; import { elevate } from "wix-auth"; // Cache the return value export const cachedMultiply = webMethod(Permissions.Anyone, (a, b) => a * b, { cache: { tags: ["multiply", "math"], ttl: 604000, }, }); // Invalidate the cache const invalidationMethods = [{ tag: "multiply" }, { tag: "math" }]; const elevatedInvalidateCache = elevate(cache.invalidateCache); export const invalidateCache = webMethod(Permissions.Anyone, async () => { try { await elevatedInvalidateCache(invalidationMethods); console.log("Successfully invalidated cache.") } catch (error) { console.error(error); // Handle the error } }); /* Promise resolves to void */ ``` ## Invalidate cached return value from queryContacts() ```javascript import { cache } from "wix-cache-backend"; import { contacts } from "wix-crm.v2"; import { webMethod, Permissions } from "wix-web-module"; import { elevate } from "wix-auth"; // Query contacts and cache result const elevatedQueryContact = elevate(contacts.queryContacts); export const myQueryContactFunction = webMethod( Permissions.Anyone, async () => { try { const contact = await elevatedQueryContact().find(); return contact.items; } catch (error) { console.log(error); // Handle the error } }, { cache: { tags: ["contact", "crm"], ttl: 85500, }, } ); // Invalidate cached query return value /* Sample invalidationMethods value: * [ * { tag: "contact" }, * { tag: "crm" } * ] */ const elevatedInvalidateCache = elevate(cache.invalidateCache); export const invalidateCache = webMethod( Permissions.Anyone, async (invalidationMethods) => { try { await elevatedInvalidateCache(invalidationMethods); return console.log("Successfully invalidated cache."); } catch (error) { console.error(error); // Handle the error } } ); ``` ---