algolia / angular-instantsearch

⚡️Lightning-fast search for Angular apps, by Algolia
https://algolia.com/doc/deprecated/instantsearch/angular/v4/api-reference/instantsearch/
MIT License
261 stars 73 forks source link

Could not find the option to clear cache or "render" the client again #973

Open johnico opened 2 years ago

johnico commented 2 years ago

Hello

1 . i have to get a new api key by user action once I update the config object , the ais-instasearch keep working with the previous api key

so i m trying to find a way to clear cache or update the config object , in order to "render again" the instance search without rendering all the component

  fetchKey(someData: string[]) {

    const data: Algolia.SearchApiKeyOnCallData = { someId, someData };
.......
    getAlgoliaApi(data)
      .toPromise()
      .then((apiKey: string) => {
        const searchClient = algoliasearch('id', apiKey);
        this.config = {
          indexName: `index`,
          searchClient,
        };
      })
      .catch((e) => {
      });

html :

  <ng-container *ngIf="config">
    <ais-instantsearch [config]="config">
    </ais-instantsearch>
   </ng-container>

2- is it possible to always query algolia without using cache request while search or using facets ? (without refresh button or smth like that)

tried searchClient.clearCache() (does not work)

Haroenv commented 2 years ago

Could it be that you're searching for Refresh? https://github.com/algolia/angular-instantsearch/blob/1a12f5ed0f2ef76f743d2b6f0790680252b368e9/examples/storybook/src/custom-widgets.ts#L106-L136

Also the cache can be disabled completely by passing:

// v3 algoliasearch
const searchClient = algoliasearch('id', 'key', { cache: false });
// v4 algoliasearch
import { createNullCache } from '@algolia/cache-common';

const searchClient = algoliasearch('id', 'key', {
 {
    // Caches responses from Algolia
    responsesCache: createNullCache()

    // Caches Promises with the same request payload
    requestsCache: createNullCache()
  },
});
johnico commented 2 years ago

@Haroenv about cache this is good. thanks

the issue is that if i replace the apiKey because i got a new client the instasne seatch still has the same client

i print the apiKey and it is the same always until i will refresh or re render the page

i figured it out only by render all component again so it will generate the html (with ng-if) from scratch but this is a bad solution for me because i got "refresh" and lost my search params

so i have the function fetchKey() that update the "this.config" with the searchClient , but its does not help the instance still with the first one i thunk might be the search client is part of config object and the angular did not recognize it a change? so at the end my goal is to replace the search client without refresh the page

so to focus the question:

i got action from user to update list based on this list i generate a new searchClient now i need to update the ui +refresh the queries on the ui because now i have a different data