[solved] Clear cache for one (currect) site only?

Talk about add-ons and extension development.
Post Reply
postcd
Posts: 54
Joined: April 5th, 2015, 6:24 am

[solved] Clear cache for one (currect) site only?

Post by postcd »

Hello,
i apologize if this is not right section, pls delete if wrong.

I seek an extension (v.57 compatible) that can clear cache for particular webpage (current web page), not all cache.
Is there any work around, is it possible to clear just on one site?

my FF: 57.0b9 32bit

There are cache related extensions:
https://addons.mozilla.org/en-US/firefo ... form=linux

I used "Clear Site Cache" but it seems to be not longer supported in v. 57.
Last edited by postcd on October 21st, 2017, 3:09 am, edited 1 time in total.
Brummelchen
Posts: 4480
Joined: March 19th, 2005, 10:51 am

Re: Clear cache for one (currect) site only?

Post by Brummelchen »

press ctrl+f5 or
https://addons.mozilla.org/en-US/firefo ... he-button/

clearing the site cache ever was futile with this built-in function or a button which includes loading and without cache where you have to clear and reload in two actions.

why simple when it can be complicated.
morat
Posts: 6421
Joined: February 3rd, 2009, 6:29 pm

Re: Clear cache for one (currect) site only?

Post by morat »

It's not possible to just clear the cached contents of the current site with the WebExtensions API.
postcd wrote:Is there any workaround?
Are you a web developer? Do you want code to run in scratchpad in the browser context?

Try this:

* open about:config tab
* set devtools.chrome.enabled pref to true
* tools > web developer > scratchpad
* environment > browser
* edit > paste (i.e. copy and paste code snippet)
* select a tab for clearing
* execute > run

Code: Select all

(function () {

  if (typeof document.getElementsByAttribute == "undefined") {

    alert("Scratchpad: not in browser context");

  } else {

    function humanBytes(bytes) {
      if (bytes < 1024) {
        return bytes + " bytes";
      } else if (bytes < 1024 * 1024) {
        return Math.round(bytes / 10.24) / 100 + " KB";
      } else {
        return Math.round(bytes / 10.24 / 1024) / 100 + " MB";
      }
    }

    try {
      var uri = gBrowser.currentURI;
      var stats = {
        host: uri.host, removed: null, total_size: null,
      };
    } catch (e) { alert("Scratchpad: can't get host"); return; }

    var cacheService = Components.classes["@mozilla.org/netwerk/cache-storage-service;1"].
      getService(Components.interfaces.nsICacheStorageService);
    var loadContextInfo = Components.classes["@mozilla.org/load-context-info-factory;1"].
      getService(Components.interfaces.nsILoadContextInfoFactory);
    cacheService.diskCacheStorage(loadContextInfo.default, false).asyncVisitStorage({
      onCacheStorageInfo: function () {},
      onCacheEntryInfo: function (aURI, aIdEnhance, aDataSize) {
        if (stats.host !== aURI.host) return;
        stats.removed++;
        stats.total_size += aDataSize;
        cacheService.diskCacheStorage(loadContextInfo.default, false).
          asyncDoomURI(uri, null, null);
      },
      onCacheEntryVisitCompleted: function () {
        alert("Scratchpad: " + (0 + stats.removed) + " entries removed (" +
          humanBytes(0 + stats.total_size) + ")");
      },
    }, true);

  }

})();
That code works for me in Fx 57.

Clear Site Cache
http://addons.mozilla.org/firefox/addon/589468

Reference
http://dxr.mozilla.org/mozilla-release/ ... ervice.idl
http://dxr.mozilla.org/mozilla-release/ ... torage.idl
http://dxr.mozilla.org/mozilla-release/ ... isitor.idl
Post Reply