Issues with images cache

Moderator
Från Lithuania
Medlem sedan mars 2016

I have issues with images cache. Uploaded new pictures to the product, but some thumbnails are left from old images.

What I did try to solve it:
Empty cache from admin panel.
Empty cache by deleting cache directory.
CTRL + F5 in the browser.

What else might I try?

LiteCart Fan
Från Thailand
Medlem sedan aug. 2017

Did you already try from another browser/computer?

jsl
LiteCart Fan
Från Malaysia
Medlem sedan mars 2018
jsl

change all the image name and upload a brand new set. i get this problem too and this is how i solve it

tim
Founder
Från Sweden
Medlem sedan maj 2013
tim

Make sure there is no server cache mechanism like Cloudflare, Supercache or similar.

Can you verify over FTP that the file in the cache folder is the old one?

Moderator
Från Lithuania
Medlem sedan mars 2016

I only managed to work by renaming the product. Then new file names were given for images.

Not sure what was the issue.

Raderad
Från Okänd

System Cache Enabled = False

It still creates cache files. Images in shipping section don't update. Some product images won't update.

Why does it use cache even if setting is false?

I literally have to delete all folders in cache directory to make this work.

tim
Founder
Från Sweden
Medlem sedan maj 2013
tim

Thumbnails Cache and System Cache are not the same. Thumbnail cache can not be turned off. Only cleared. See Settings -> Images. Thumbnail generation eats too much ram and cpu on the server.

You can also manually delete all subfolders in cache/ to start off fresh.

Raderad
Från Okänd

Ok that makes sense. Thanks

Merchant
Från United Kingdom
Medlem sedan apr. 2023

My son who manages my site, came across a similar issue while building an admin app that applies stickers to the main product image and he used Tims suggestion of using the following function :

function image_delete_cache($file) {

    $webpath = preg_replace('#^('. preg_quote(FS_DIR_APP, '#') .')#', '', str_replace('\', '/', $file));

    $cachename = sha1($webpath);

    $files = glob(FS_DIR_APP . 'cache/' . $cachename .'*');

    if ($files) foreach ($files as $file) {
      unlink($file);
    }
  }

As this function is already declared, All he needed to do was put the following line after the code that saves the Image:

//The code in our admin app that saves the processed image
$image = current($product->data['images']);
$outputImagePath = FS_DIR_STORAGE . 'images/' . $image['filename'];
           

Below is the code you would use to clear the cache. but you probably would be using some other name than $outputImagePath

// Delete cached versions of the processed image
image_delete_cache($outputImagePath);

Hope this helps

Merchant
Från United Kingdom
Medlem sedan apr. 2023

We found that the above method of using image_delete_cache($outputImagePath); didn't always work so well, so we use the following method that has worked every time so far:

<?php
header('Expires: Fri, 20 Jan 1984 01:11:11 GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
?>

Merchant
Från United Kingdom
Medlem sedan apr. 2023

Although the above solution works in the app my son has made, It doesn't work with the rest of the website for thumbnails.  I know we can go to settings / images and delete cache from there but that's not what we want as we are working on only one image we don't want to delete the whole cache of images. I was wondering if there is a solution to just delete the cached thumbnails of the image we are working on.

Merchant
Från United Kingdom
Medlem sedan apr. 2023

I know we could do things like renaming the edited image but that would also need a database update to reflect the new image name. However this is not an option in the app my son has built because the app is part of his college course and the tutor has set strict guidelines. One of those guidelines being that the app must not perform any updates to the database or permanently alter the original codebase. Although technology such as Vmods are allowed.

tim
Founder
Från Sweden
Medlem sedan maj 2013
tim

If you have a browser cache problem, try outputting the image url with rlink() for resource URLs. Note FS for filesystem paths and not WS.
<img src="<?php echo document::href_rlink(FS_DIR_APP . 'path/to/image.jpg'); ?>">

If you have a problem with server cache, that is resolved by cleaning the thumbnails cache under Admin -> Settings -> Images or run the individual command image_delete_cache($image_path).

If you have a problem with CDN cache, empty the cache at the CDN service and always use rlink() to output image resources.

https://wiki.litecart.net/introduction#links

Du
Denna webbplats använder inga kakor och ingen spårningsteknik från tredje part . Vi tror att vi kan göra det bättre än andra och tänker verkligen på din integritet.