如何在Firefox中使用XPCOM组件从缓存中获取图像 [英] How to get images from cache using a XPCOM Component in Firefox

查看:98
本文介绍了如何在Firefox中使用XPCOM组件从缓存中获取图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要获取文档中加载的所有图像的缓存文件路径,我想知道为此需要使用哪些接口

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

推荐答案

这是我用来逐出缓存条目的方法:

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.

这篇关于如何在Firefox中使用XPCOM组件从缓存中获取图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆