TagCache.invalidate() method

Invalidates data under given tags

Walks each given tag's set in batches of INVALIDATE_BATCH members, deleting those keys and removing them from that tag, one awaited MULTI per batch. Memory and command size are bounded by the batch, whatever the size of the tag or of the keyspace.

Three properties worth knowing, because none is obvious from the signature:

  • **It resolves once the keys are gone.** Every batch is awaited, so a true result means the tagged values have been deleted. - **Other tags are not scrubbed.** A deleted key may still be a member of a tag that was not invalidated. That is harmless — invalidating that tag later deletes a key that no longer exists, and a tag set given a ttl expires with it. Scrubbing every tag here costs tags x keys, which is what took a service's heap from 564MB to 15GB on one invalidation of a tag holding 15,000 keys in a keyspace of 3,000 tags. - **A value cached during the invalidation stays tagged.** Only the members that were scanned are removed from the tag, so a later invalidation still reaches anything added meanwhile.

Signature:

invalidate(...tags: string[]): Promise<boolean>;

Parameters

Parameter

Type

Description

tags

string[]

one or more tags whose data should be dropped

Returns:

Promise<boolean>

true once every tagged key is deleted, including the case where the tags held no keys at all; false if redis failed part-way, which is logged rather than thrown

Exceptions

TypeError when there is no redis connection — see REDIS_INIT_ERROR

Read this page as plain markdown — no HTML, no navigation. For pasting into an LLM, or for an agent to fetch.