This PR exposes a new method, clearCache on SearchClient which allows for a user to programmatically clear the Typesense client cache. Which is useful for having instant access to new documents after mutations.
To do this, I had to create a method to reset the cache in RequestWithCache and then "bubble up" this method through Multisearch and SearchOnlyDocuments to finally expose it in the SearchClient class. Alternatively it might be nice to instantiate the cache at the SearchClient level to pass it down, but I didn't want to mess with current implementations.
To clear cache, multisearch is straight forward but with individual collections, we must loop through all collections to reset.
I also added two tests to SearchClient, which confirm that the cache is being reset properly, but I'm not sure this is the best location or implementation for them.
Hope this helps or gets us in the right direction!
Change Summary
This PR exposes a new method,
clearCache
onSearchClient
which allows for a user to programmatically clear the Typesense client cache. Which is useful for having instant access to new documents after mutations.To do this, I had to create a method to reset the cache in
RequestWithCache
and then "bubble up" this method throughMultisearch
andSearchOnlyDocuments
to finally expose it in theSearchClient
class. Alternatively it might be nice to instantiate the cache at theSearchClient
level to pass it down, but I didn't want to mess with current implementations.To clear cache, multisearch is straight forward but with individual collections, we must loop through all collections to reset.
I also added two tests to
SearchClient
, which confirm that the cache is being reset properly, but I'm not sure this is the best location or implementation for them.Hope this helps or gets us in the right direction!
PR Checklist