Option for user to clear cache folder


#1

When setting the storage location there is a lot of data written, cache folder included.

Pretty sure there is a way to clear the cache folder upon exit, but have not used that function. Rather not if possible…

What I am looking for is allow the user to clear the cache (maybe using a button). Sometimes our software pulls in updates from the net and clearing the cache folder ensure the updates are shown on next restart of the software.

Could you please provide me example code to use with a button if possible?

Much appreciated.


#2

The problem is that we have a function to delete single files, not entire folders.
As an alternative, you could try:


#3

Thanks for reply. Was hoping to allow users to clear the cache instead of clearing upon every use (or exit).

Will continue my search and see if can find solution.

Susan


#4

This still remains to be a huge problem (at least for me).

Apparently EXEOut / Chromium does not respect the following:

header(‘Cache-Control: no-cache, no-store, must-revalidate’);
header(‘Pragma: no-cache’);
header(‘Expires: 0’);

OR

	<meta http-equiv="cache-control" content="max-age=0" />
	<meta http-equiv="cache-control" content="no-store" />
	<meta http-equiv="expires" content="-1" />
	<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
	<meta http-equiv="pragma" content="no-cache" />

When using upload functions (images for example) the past images are cached and will show even new image has been uploaded. Only way to get new image to show is exit and restart the software.

This is show stopper for me and have had to use other methods to build my software.

Is there any way to force reload of a page and clear the page cache? Even disabling local cache has no effect.

I do not want to choose the option to NOT create a storage folder and even if did, would fix the problem. User would still have to exit the software.


#5

The correct way for an image not to be cached is to use a key for image, for example:
Example :
<?php
$key = rand(0,35);
$imagekey = “&key=”.$key;
echo “< img src=‘mydir/img/img.jpg$imagekey’ >”
?>

I do not know if that’s your question … when I work with image, I like using the key to remove the cache.

Good luck.


#6

Thank you @wayos. As always your input is invaluable.

Having issues with images and some .js files. Using your input for image ideas, have found way that works for me:

myimage.jpg?nocache=<?php echo time(); ?>

This works every time without fail (at least in my tests). In my case uploading an image that always remains the same name so this ensures new name when page is reloaded:)

Got to find a way to clear the .js files when needed, but that is minor at this time.

Thanks again for taking time to reply.


#7

The same as for .jpg files will work. myscript.js?mytime=…


#8

Makes PERFECT sense, was over thinking the process. Thanks for waking me up:)


#9

If you are going to use ajax (jquery) just use the cache:
1 ------------------------------------------
$.ajaxSetup({
cache: false;
});

2 -------------------------------------------- OR
jQuery.cachedScript = function( url, options ) {

      // Allow user to set any option except for dataType, cache, and url
      options = $.extend( options || {}, {
        dataType: "script",
        cache: false,
        url: url
      });
     
      // Use $.ajax() since it is more flexible than $.getScript
      // Return the jqXHR object so we can chain callbacks
      return jQuery.ajax( options );
    };
     
    // Usage
    $.cachedScript( "ajax/test.js" ).done(function( script, textStatus ) {
      console.log( textStatus );
    });

#10

Great tip @wayos! I have never tried that on my ajax forms, will have to test it out.

Thanks!