【问题标题】:nsICacheService doesn't work in Firefox 38nsICacheService 在 Firefox 38 中不起作用
【发布时间】:2015-06-14 10:53:31
【问题描述】:

我用

Components.classes["@mozilla.org/network/cache-service;1"].getService(Components.interfaces.nsICacheService);

在开发 Firefox 扩展时操作 http 缓存。

但是我升级到Firefox 38 esr后,这个接口在调用它的函数时会抛出错误

[Exception... "Component returned failure code: 0x80004001 (NS_ERROR_NOT_IMPLEMENTED) [nsICacheService.visitEntries]" nsresult: "0x80004001 (NS_ERROR_NOT_IMPLEMENTED)"

而且我没有发现它在 MDN 中过时,所以有人知道为什么吗?非常感谢。

【问题讨论】:

  • 这是一个非常酷的工作,缓存的东西在 MDN 上没有很好的记录,你看到这个话题了吗:stackoverflow.com/questions/27842615/… 这不完全是你的问题,但它的缓存工作也是如此。能否请您链接到您的开源代码,我很想从中学习如何使用nsICacheService

标签: javascript firefox firefox-addon


【解决方案1】:

http://code.metager.de/source/xref/mozilla/firefox/netwerk/cache/nsICacheService.idl

这看起来像是一个提示 * 当首选使用缓存 v2 时,@throws NS_ERROR_NOT_IMPLEMENTED。

https://bugzilla.mozilla.org/show_bug.cgi?id=913807

我在想,我们需要做的就是在

的这一行中将 1 更改为 2

var cacheService = cc["@mozilla.org/network/cache-service;1"] .getService(ci.nsICacheService);

【讨论】:

    【解决方案2】:

    我尝试了这段代码,它抛出:(复制粘贴在浏览器环境中的 scratcpad 中运行 - https://www.youtube.com/watch?v=oo4STWceGTM

    var cacheService = Cc["@mozilla.org/network/cache-service;1"].getService(Ci.nsICacheService);
    console.log('cacheService:', cacheService);
    
    function CacheVisitor(){}
    
    CacheVisitor.prototype = {
        QueryInterface : function(iid)
        {
            if (iid.equals(Ci.nsICacheVisitor))
                return this;
            throw Components.results.NS_NOINTERFACE;
        },
    
        visitDevice : function(deviceID, deviceInfo)
        {
            console.log("[visiting device (deviceID = ", deviceID ,", description = ", deviceInfo.description ,")]");
            return true;
        },
    
        visitEntry : function(deviceID, entryInfo)
        {
            console.log("[visiting entry (clientID = ", entryInfo.clientID, "key = ", entryInfo.key, ")]");
            return true;
        }
    };
    var visitor = new CacheVisitor();
    cacheService.visitEntries(visitor); // throws on this line here!!!
    

    它在cacheService.visitEntries(visitor); // throws on this line here!!! 线上抛出它抛出这个:

    /*
    Exception: [Exception... "Component returned failure code: 0x80004001 (NS_ERROR_NOT_IMPLEMENTED) [nsICacheService.visitEntries]"  nsresult: "0x80004001 (NS_ERROR_NOT_IMPLEMENTED)"  location: "JS frame :: Scratchpad/1 :: <TOP_LEVEL> :: line 27"  data: no]
    */
    

    这与您遇到的问题相同。你能验证一下吗,我没有看到你的可重现代码。

    【讨论】:

    • 是的,就像你的代码一样,当调用 cacheService.visitEntries() 时,它会抛出错误。
    • 来自 MozillaZine,他们告诉我 nsICacheService 已标记为删除。详情:forums.mozillazine.org/viewtopic.php?f=19&t=2940611
    • 在上面的代码中,visitEntries() 没有定义,只有 visitEntry() 可能是这个问题吗?
    • 谢谢@Githlar 我不确定,但实际上它已被弃用,取而代之的是与 mozillazine 主题相关联的新缓存系统:developer.mozilla.org/en-US/docs/HTTP_Cache
    猜你喜欢
    • 2015-08-10
    • 2012-11-27
    • 2012-02-27
    • 2017-02-08
    • 2014-08-23
    • 2013-07-12
    • 2016-06-13
    • 2017-08-19
    • 2015-03-16
    相关资源
    最近更新 更多