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.

Clearing cache not working

See original GitHub issue

Hi,

I’m trying to clear the cache under ionic 4 in iOS.

My code looks like this:

const filesBefore = await this.file.listDir(this.file.cacheDirectory, 'image-loader-cache');
console.log('Files before:', filesBefore);
await this.imageLoader.clearCache();
const filesAfter = await this.file.listDir(this.file.cacheDirectory, 'image-loader-cache');
console.log('Files after:', filesAfter);

In the console it looks like this:

Files before: [Array] (306)
Files after: [Array] (306)

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
pcsantanacommented, Mar 17, 2020

Thank you @Bart1909 To solve the problem of delete the old image, I did a method to remove the cached file. It works! But while I doesn’t restart the app, the image not change (dont know why). So, to change it instantly I ended up doing the same approach as you, adding a query parameter to load again.

If anyone wants, to remove the cached file:

async removeCacheFile(myImagePath: string): Promise<void> {
    try {
        const cachePath: string = await this.imageLoader.getImagePath(myImagePath);
        const filename: string = cachePath.substr(cachePath.lastIndexOf('/') + 1);
        const exists: boolean = await this.file.checkFile(this.file.cacheDirectory + "image-loader-cache/", filename);
        if (exists) {
            await this.file.removeFile(this.file.cacheDirectory + "image-loader-cache/", filename);
        }
    } catch (error) {
        console.error(error);
    }
}
1reaction
gaurav-chandracommented, Mar 24, 2020

thanks @pcsantana for your code. This works.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Chrome WON'T clear cache... ctrl + F5 doesn't seem to work ...
Click on the 3 vertical dots on the top right corner of the browser · Click on "More tools" · Click on "Clear...
Read more >
How to clear cache and cookies (Chrome hard refresh)
To clear your cache and cookies on Chrome, open the Chrome Menu and select Clear Browsing Data. Another keyboard shortcut to access this...
Read more >
Clear cache & cookies - Computer - Google Account Help
On your computer, open Chrome. · At the top right, click More More . · Click More tools and then Clear browsing data....
Read more >
How to Clear the Cache and Cookies in Your Web Browser
Clearing the cache and cookies from a web browser is an important first-step for almost any troubleshooting for internet browsing.
Read more >
Troubleshooting: Clearing Browser Cache & Cookies
Troubleshooting : Clearing Browser Cache & Cookies · What's in this article: · How to clear your cookies and cache by browser: ·...
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