Open Bart1909 opened 4 years ago
Hi @Bart1909 ! Did you find a solution? Thanks!
Hi @pcsantana, no, not really. I'm doing a "workaround" with adding a query parameter to my urls, when changing the image on the backend. E.g. the url is https://mydomain.com/public/images/img1.jpg?timestamp=1584461500 When I change the image, i change the timestamp to current time. So the url is different and the image will be downloaded again. The disadvantage is, that the old image will retain on the device. But due to the fact, that my images do not change so often, this will be fine at the moment until the problem will be fixed.
Best wishes
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);
}
}
thanks @pcsantana for your code. This works.
Will there be a fix?
@pcsantana 's code is not a solution because you're clearing the cache of a single file. Here we're pointing out that the method used to clear ALL cache is not working anymore.
@Bart1909 how did you even manage to run the code? I get a "Property 'clearCache' does not exist on type 'IonicImageLoader'.", the method to clear all the cache data doesn't even exist anymore, what's happening?
Hi,
I'm trying to clear the cache under ionic 4 in iOS.
My code looks like this:
In the console it looks like this: