Skip to content

Response cache with backend search #1575

@PaulWild

Description

@PaulWild

Description

Our company is currently utilising a backend search as described by https://www.algolia.com/doc/guides/building-search-ui/going-further/backend-search/in-depth/backend-instantsearch/js/.

Implementing this as far as I can tell means that these requests aren't cached in the client's inbuilt responseCache.

Is there any guidance/ability to hook up custom searches to the responseCache? Would something like this work? :

export const customSearchClient = {
  ...algoliaSearchClient,
  async search<TObject>(requests: readonly MultipleQueriesQuery[]) {
    const key = { requests };

    return algoliaSearchClient.transporter.responsesCache.get(key, async () => {
      const response: Readonly<Promise<MultipleQueriesResponse<TObject>>> = customServerRequest()

      await algoliaSearchClient.transporter.responsesCache.set(key, response);
      return response;
    });
  }

Client

Search

Version

all

Relevant log output

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions