How to get images from cache using a XPCOM Compone

2019-08-21 02:28发布

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条回答
贼婆χ
2楼-- · 2019-08-21 03:09

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.

查看更多
登录 后发表回答