Skip to content

docs: clarify how to fully clear a selector's cache (#569) - #760

Open
veksa wants to merge 2 commits into
reduxjs:masterfrom
veksa:fix/569-clearing-selector-cache
Open

docs: clarify how to fully clear a selector's cache (#569)#760
veksa wants to merge 2 commits into
reduxjs:masterfrom
veksa:fix/569-clearing-selector-cache

Conversation

@veksa

@veksa veksa commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #569.

A memoized selector keeps two separate caches because of Reselect's
two-stage "cascading" memoization:

  • the argsMemoize cache for the arguments passed to the output selector,
    attached to the selector itself (selector.clearCache());
  • the memoize cache for the input selectors' results, attached to
    memoizedResultFunc (selector.memoizedResultFunc.clearCache()).

selector.clearCache() only clears the first one. This trips people up when
they try to reset a selector between tests and see stale memoized results — the
exact confusion reported in #569.

Note: the original type error from that issue was on v4. On v5 the types are
already correct — both .clearCache() accesses type-check on default and lru
selectors (verified with tsc). So the real gap was purely documentation; this
PR documents the behavior and adds a regression type test to lock it in.

Changes

Docs

  • FAQ.mdx – add a note in "How do I test a selector?" explaining the two
    caches and showing how to fully reset a selector between tests.
  • api/createSelector.mdx – add a "Clearing the cache" note under the Output
    Selector Fields table.

Types

  • src/types.ts – expand the JSDoc on memoizedResultFunc and clearCache so
    the dual-cache behavior shows up in IDE hovers.
  • typescript_test/argsMemoize.typetest.ts – add a type test asserting that
    clearCache / resultsCount / resetResultsCount exist on both a default
    selector and its memoizedResultFunc.

Testing

  • tsc --noEmit -p typescript_test/tsconfig.json passes.

@netlify

netlify Bot commented Jul 19, 2026

Copy link
Copy Markdown

Deploy Preview for reselect-docs canceled.

Name Link
🔨 Latest commit 4a7ff20
🔍 Latest deploy log https://app.netlify.com/projects/reselect-docs/deploys/6a6703bf01953800088c52a9

@codesandbox-ci

codesandbox-ci Bot commented Jul 19, 2026

Copy link
Copy Markdown

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@aryaemami59 aryaemami59 added the Documentation Improvements or additions to documentation label Jul 26, 2026
@veksa
veksa force-pushed the fix/569-clearing-selector-cache branch from 4f8bd91 to 4a7ff20 Compare July 27, 2026 07:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

clear lastResult between tests

2 participants