How to get images from cache using a XPCOM Component in Firefox

假如想象 提交于 2020-01-07 04:41:37

问题


I need to get the cache file path for ever image loaded in a document, I am wondering what are the Interfaces I need to use in order to do that

https://developer.mozilla.org/en/XPCOM_Interface_Reference


回答1:


This is what I used to evict cache entry:

  function removeItem(url){
    let cacheService = Components.classes["@mozilla.org/network/cache-service;1"]
                            .getService(Components.interfaces.nsICacheService);
    var Ci = Components.interfaces;
    var session = cacheService.createSession("image", Ci.nsICache.STORE_ANYWHERE, false);
    if(!session){
        return;
    }

    var entry;
    try{
        entry = session.openCacheEntry(url, Ci.nsICache.ACCESS_READ, false);
        if(!entry){
            return;
        }
    }catch(ex){
        return;
    }

    entry.doom();
    entry.close();
  }
}

Once you have entry you should be able to open a stream to it - possibly getting the content or even replacing it - I haven't tried it though.



来源:https://stackoverflow.com/questions/4785455/how-to-get-images-from-cache-using-a-xpcom-component-in-firefox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!