question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Do you have example of using createAlgoliaClient to clear the cache?

See original GitHub issue

I am trying to programmatically update the cache in my component.

Html

<button (click)="updateCache()">update<button>
<ng-ais-instantsearch [config]="algoliaEnv" >
<ng-ais-search-box></ng-ais-search-box>
<ng-ais-hits></ng-ais-hits>

Component

this.algoliaEnv = {
      apiKey: <api-key>,
      appId: <app-id>,
      indexName: <index-name>,
      createAlgoliaClient: this.testFunction,
};

testFunction(customClient: Function, appId: string, apiKey: string) {
  // How do I use customClient here ?
  const algoliaSearch: algoliasearch.AlgoliaClient = customClient(appId, apiKey);
  return algoliaSearch;
}

updateCache(){
  // What should I call here?
}

The above code does not throw any errors, but I am trying to figure out how to update the cache programmatically, for example inside the updateCache method. The documentation states: “We forward algoliasearch which is the original algoliasearch module imported inside angular-instantsearch.” - but how do I use this?

I really hope you can help me out here 😃

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
Haroenvcommented, Feb 15, 2018

You were almost there, the function is called refresh and is on the instantSearchInstance, and you also need to implement the button in your app.

I forked your sandbox: here is my version with the necessary changes.

Changes are:

app.component.html: L83: <custom-widget></custom-widget> custom-widget.ts:

import { Component, Inject, forwardRef, OnInit } from "@angular/core";
import { NgAisInstantSearch } from "angular-instantsearch";

@Component({
  selector: "custom-widget",
  templateUrl: "./custom-widget.component.html"
})
export class CustomWidgetComponent {
  state: {
  };

  constructor(
    @Inject(forwardRef(() => NgAisInstantSearch))
    public instantSearchParent
  ) {}

  refresh() {
    this.instantSearchParent.instantSearchInstance.refresh();
  }
}

custom-widget.component.html:

<button (click)="refresh()">Refresh</button>

cc @compuIves, I also manage to get my browser crashing with the custom widget (but the code is correct)

1reaction
brunoFreibergercommented, Aug 22, 2018

I used code of your comment and now it’s working, thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Clear cache & cookies - Computer - Google Account Help
When you use a browser, like Chrome, it saves some information from websites in its cache and ... For example, you can delete...
Read more >
How to Clear Cache on Android (And When You Should)
Choose the app whose cache you want to clear. To see which apps are taking the most space, tap the three-dot menu in...
Read more >
How to Clear the Cache and Cookies in Your Web Browser
Keyboard Shortcut for Most Browsers. If you are using Internet Explorer, Edge, Google Chrome, or Mozilla Firefox you can quickly clear cache ......
Read more >
What Is Cached Data and Should You Keep it or Clear it?
When this data is cached, we can reopen the app or revisit the page with confidence that it won't take anywhere near as...
Read more >
What is a cache? And why does clearing it fix things?
It's timeless advice: if a website isn't loading properly, clear your browser's cache. We've all done it, noticed that things work again, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found