Support » Plugin: Autoptimize » Schedule cache purge

  • Resolved Allon Sacks

    (@allonsacksgmailcom)


    Hi,

    I read the faq but on one of my sites if I disable aggregating js and enable force js in the head, it still breaks the site.
    The cache is growing to over 500mb…
    Is there a way to schedule a cache purge?
    I could us a cron job or wp-cron, just need a line of code that causes the cache to purge.
    Appreciated. Thanks!

    https://wordpress.org/plugins/autoptimize/

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Frank Goossens

    (@futtta)

    maybe you have inline CSS that is busting the cache, it’s not that common but it does happen.

    re. your cron-job;
    autoptimizeCache::clearall()

    should work 🙂

    Allon Sacks

    (@allonsacksgmailcom)

    Thanks you rock!

    Allon Sacks

    (@allonsacksgmailcom)

    Hey, so I have been digging around a bit in the code, I want to clear the cache once it reaches a certain size.
    Is there a good way to check I think I have it something like this:

    $myMaxSize = 256000;
    $statArr=autoptimizeCache::stats(); 
    $cacheSize=round($statArr[1]/1024);
    if (($cacheSize>$myMaxSize){
       autoptimizeCache::clearall()
    }

    Thanks!

    Plugin Author Frank Goossens

    (@futtta)

    code looks OK allonsacksgmailcom, but don’t kill the canary! 😉

    Allon Sacks

    (@allonsacksgmailcom)

    Thanks! I will try it out, looks like I actually got the solution while writing you the question… I actually started writing the question before I had finished and by the time I posted it was kinda I could just test this instead of asking but anyway I appreciate your input and this can help others…

    TTLY agree with you about the canary but some clients are small and do not have the budget for me to sort out all the issues to have standardized js and css across the site so emptying the cache every few days is a viable solution. In any case I try to use cache preload and changes in the background require the cache refresh itself every few days.

    Are you thinking of adding preload and cache timeout at any point?

    Plugin Author Frank Goossens

    (@futtta)

    Are you thinking of adding preload and cache timeout at any point?

    who knows, maybe one day 🙂

    Allon Sacks

    (@allonsacksgmailcom)

    Ok so I tested and the following code works by simple dropping it into the functions.php.
    This means that instead of using wp-cron and clearing on set days regardless of cache size, the cache this way is cleared when it reaches the size you define.

    $myMaxSize = 350000;
    $statArr=autoptimizeCache::stats();
    $cacheSize=round($statArr[1]/1024);
    if (($cacheSize>$myMaxSize)){
    	autoptimizeCache::clearall();
    }

    I have updated the code slightly and you may add this on the Top of functions.php

    
    # Automatically clear autoptimizeCache if it goes beyond 256MB
    if (class_exists('autoptimizeCache')) {
    	$myMaxSize = 256000; # You may change this value to lower like 100000 for 100MB if you have limited server space
    	$statArr=autoptimizeCache::stats(); 
    	$cacheSize=round($statArr[1]/1024);
    	
    	if ($cacheSize>$myMaxSize){
    	   autoptimizeCache::clearall();
    	   header("Refresh:0"); # Refresh the page so that autoptimize can create new cache files and it does breaks the page after clearall.
    	}
    }
    
    • This reply was modified 3 years, 3 months ago by rahulpragma.
    • This reply was modified 3 years, 3 months ago by rahulpragma. Reason: Added Comments
    • This reply was modified 3 years, 3 months ago by rahulpragma. Reason: Updated Code
Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Schedule cache purge’ is closed to new replies.