Jump to content

Problem with smarty cache - How to clear only css cache


JParriki

Recommended Posts

Hello community,

 

I would like to know if it is possible to clear only the css cache from a module.

 

I have a module with styles and javascript but without views (I only use the hookDisplayHeader on the module).

I only use it to make my own styles and javascript without have to touch any other css files.

 

The problem is that when I make a change, some users don´t see the change because they have the file on cache.

 

I tried to use the Cache class from prestahop but it doesn´t work,  I think I don´t use the class on right way.
 

Other thing that I tried, was to put on the htacces the following code, but it didn´t work.

 

 

<filesMatch "\.(html|htm|js|css|php)$">
FileETag None
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
</filesMatch>
 

 

I also wrote on the main "index.php", that is on the root folder, this code:

 

 

header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 1 Jul 2000 05:00:00 GMT"); // Fecha en el pasado

 

Anyone can help me?

 

PD: Sorry for my English

Link to comment
Share on other sites

  • 2 years later...
  • 10 months later...
  • 1 year later...
/**
 * Clear theme cache.
 */
public static function clearCache()
{
    $files = array_merge(
        glob(_PS_THEME_DIR_ . 'assets/cache/*', GLOB_NOSORT),
        glob(_PS_THEME_DIR_ . 'cache/*', GLOB_NOSORT)
    );

    foreach ($files as $file) {
        if ('index.php' !== basename($file)) {
            Tools::deleteFile($file);
        }
    }

    $version = (int) Configuration::get('PS_CCCJS_VERSION');
    Configuration::updateValue('PS_CCCJS_VERSION', ++$version);
    $version = (int) Configuration::get('PS_CCCCSS_VERSION');
    Configuration::updateValue('PS_CCCCSS_VERSION', ++$version);
}

This with some adjustments should fit anyones needs 😁 

File: classes/Media::clearCache()

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...