How to manually clear the cache of my algolia index?

3.5k Views Asked by At

I'm using the algolia client directly in my node js backend so i don't use instantsearch.js.

I can easily querying/indexing/updating etc. my algolia index but i can't find a way to clear the cache because my app always need to display an updated hits list in real time.

i've tried

client.initIndex('my index');
client.clearCache()

But without success. Always need to force unmount/remount manually my app to see the updated hits list.

Any solution ?

1

There are 1 best solutions below

5
On

Its an old question but since there are no responses ....

Docs

Given the following instantiation:

const client = algoliasearch('H58KBL9VKQ', '••••••••••••••••••••');
const index = client.initIndex('your_index_name');

There are two methods.

client.clearCache() - when using multiple indices

index.clearCache() - when querying one index specifically

Note that BOTH return a Promise and both work only in the BROWSER, since the Node API doesn't cache results, there is no cache to clear.