Bug 1944310 Comment 8 Edit History

Note: The actual edited comment in the bug view page will always show the original commenter’s name and original timestamp.

> 1. Does clearOrigin work for you? Under the hood both these APIs eventually get to a shared EvictByContextInternal, at least in some cases.

No, `clearOrigin` doesn't work for me.

I'm already using [`clearOrigin`](https://searchfox.org/mozilla-central/rev/5e7382bf8bbb88d8260c72990cfea9b626d9b307/netwerk/cache2/nsICacheStorageService.idl#48-54) (it is the only one that accepts the principal as argument). The corresponding C++ implementation is [`CacheStorageService::ClearOrigin`](https://searchfox.org/mozilla-central/rev/e8da1e780e9b8ed2fd82a3b8d79c5f93e72697d3/netwerk/cache2/CacheStorageService.cpp#698). It uses [mozilla::net::CacheFileIOManager::EvictByContextInternal](https://searchfox.org/mozilla-central/rev/e8da1e780e9b8ed2fd82a3b8d79c5f93e72697d3/netwerk/cache2/CacheFileIOManager.cpp#3214) under the hood, indeed.

Unfortunately the test that accomponies Bug 1819147 doesn't fail when switching back from `EqualsIgnoringFPD` to `Equals`. I'm investigating how to check whether a cache item exists. Trying stuff like (but that doesn't work yet):

```js
  chan.loadInfo.originAttributes = { userContextId: 0, partitionKey: `(https,example.com)` };
  // [...]
  let exists = cache_storage.exists(make_uri(url), "O^partitionKey=%28https%2Cexample.com%29,");
```
> 1. Does clearOrigin work for you? Under the hood both these APIs eventually get to a shared EvictByContextInternal, at least in some cases.

No, `clearOrigin` doesn't work for me.

I'm already using [`clearOrigin`](https://searchfox.org/mozilla-central/rev/5e7382bf8bbb88d8260c72990cfea9b626d9b307/netwerk/cache2/nsICacheStorageService.idl#48-54) (it is the only one that accepts the principal as argument). The corresponding C++ implementation is [`CacheStorageService::ClearOrigin`](https://searchfox.org/mozilla-central/rev/e8da1e780e9b8ed2fd82a3b8d79c5f93e72697d3/netwerk/cache2/CacheStorageService.cpp#698). It uses [mozilla::net::CacheFileIOManager::EvictByContextInternal](https://searchfox.org/mozilla-central/rev/e8da1e780e9b8ed2fd82a3b8d79c5f93e72697d3/netwerk/cache2/CacheFileIOManager.cpp#3214) under the hood, indeed.

Unfortunately the test that accomponies Bug 1819147 doesn't fail when switching back from `EqualsIgnoringFPD` to `Equals`. I'm investigating how to check whether a cache item exists. Trying stuff like (but that doesn't work yet):

[/netwerk/test/unit/test_cache2_clear_with_usercontext_oa.js#28-54](https://searchfox.org/mozilla-central/rev/e8da1e780e9b8ed2fd82a3b8d79c5f93e72697d3/netwerk/test/unit/test_cache2_clear_with_usercontext_oa.js#28-54)
```js
  chan.loadInfo.originAttributes = { userContextId: 0, partitionKey: `(https,example.com)` };
  // [...]
  let exists = cache_storage.exists(make_uri(url), "O^partitionKey=%28https%2Cexample.com%29,");
```

However when using the disk cache I get [`NS_ERROR_UNAVAILABLE`](https://searchfox.org/mozilla-central/rev/e8da1e780e9b8ed2fd82a3b8d79c5f93e72697d3/netwerk/cache2/CacheStorageService.cpp#1718-1721). Switching over to `"memory"` cache, `exists` is always `false`, no matter what I try to pass for `const nsACString& aIdExtension` (not sure whether that really is what would be passed for retrieving `partitionKey`).
> 1. Does clearOrigin work for you? Under the hood both these APIs eventually get to a shared EvictByContextInternal, at least in some cases.

No, `clearOrigin` doesn't work for me.

I'm already using [`clearOrigin`](https://searchfox.org/mozilla-central/rev/5e7382bf8bbb88d8260c72990cfea9b626d9b307/netwerk/cache2/nsICacheStorageService.idl#48-54) (it is the only one that accepts the principal as argument). The corresponding C++ implementation is [`CacheStorageService::ClearOrigin`](https://searchfox.org/mozilla-central/rev/e8da1e780e9b8ed2fd82a3b8d79c5f93e72697d3/netwerk/cache2/CacheStorageService.cpp#698). It uses [mozilla::net::CacheFileIOManager::EvictByContextInternal](https://searchfox.org/mozilla-central/rev/e8da1e780e9b8ed2fd82a3b8d79c5f93e72697d3/netwerk/cache2/CacheFileIOManager.cpp#3214) under the hood, indeed.

Unfortunately the test that accomponies Bug 1819147 doesn't fail when switching back from `EqualsIgnoringFPD` to `Equals`. I'm investigating how to check whether a cache item exists. Trying stuff like (but that doesn't work yet):

[/netwerk/test/unit/test_cache2_clear_with_usercontext_oa.js#28-54](https://searchfox.org/mozilla-central/rev/e8da1e780e9b8ed2fd82a3b8d79c5f93e72697d3/netwerk/test/unit/test_cache2_clear_with_usercontext_oa.js#28-54)
```js
  chan.loadInfo.originAttributes = { userContextId: 0, partitionKey: `(https,example.com)` };
  // [...]
  let exists = cache_storage.exists(make_uri(url), "O^partitionKey=%28https%2Cexample.com%29,");
```

However when using the disk cache I get [`NS_ERROR_UNAVAILABLE`](https://searchfox.org/mozilla-central/rev/e8da1e780e9b8ed2fd82a3b8d79c5f93e72697d3/netwerk/cache2/CacheStorageService.cpp#1718-1721). Switching over to `"memory"` cache, `exists` is always `false`, no matter what I try to pass for [`const nsACString& aIdExtension`](https://searchfox.org/mozilla-central/rev/e8da1e780e9b8ed2fd82a3b8d79c5f93e72697d3/netwerk/cache2/CacheEntry.cpp#271) (not sure whether that really is what would be passed for retrieving `partitionKey`).
> 1. Does clearOrigin work for you? Under the hood both these APIs eventually get to a shared EvictByContextInternal, at least in some cases.

No, `clearOrigin` doesn't work for me.

I'm already using [`clearOrigin`](https://searchfox.org/mozilla-central/rev/5e7382bf8bbb88d8260c72990cfea9b626d9b307/netwerk/cache2/nsICacheStorageService.idl#48-54) (it is the only one that accepts the principal as argument). The corresponding C++ implementation is [`CacheStorageService::ClearOrigin`](https://searchfox.org/mozilla-central/rev/e8da1e780e9b8ed2fd82a3b8d79c5f93e72697d3/netwerk/cache2/CacheStorageService.cpp#698). It uses [mozilla::net::CacheFileIOManager::EvictByContextInternal](https://searchfox.org/mozilla-central/rev/e8da1e780e9b8ed2fd82a3b8d79c5f93e72697d3/netwerk/cache2/CacheFileIOManager.cpp#3214) under the hood, indeed.

Unfortunately the test that accomponies Bug 1819147 doesn't fail when switching back from `EqualsIgnoringFPD` to `Equals`. I'm investigating how to check whether a cache item exists. Trying stuff like (but that doesn't work yet):

[/netwerk/test/unit/test_cache2_clear_with_usercontext_oa.js#28-54](https://searchfox.org/mozilla-central/rev/e8da1e780e9b8ed2fd82a3b8d79c5f93e72697d3/netwerk/test/unit/test_cache2_clear_with_usercontext_oa.js#28-54)
```js
  chan.loadInfo.originAttributes = { userContextId: 0, partitionKey: `(https,example.com)` };
  // [...]
  let exists = cache_storage.exists(make_uri(url), "O^partitionKey=%28https%2Cexample.com%29,");
```

However when using the disk cache I get [`NS_ERROR_UNAVAILABLE`](https://searchfox.org/mozilla-central/rev/e8da1e780e9b8ed2fd82a3b8d79c5f93e72697d3/netwerk/cache2/CacheStorageService.cpp#1718-1721). Switching over to `"memory"` cache, `exists` is always `false`, no matter what I try to pass for [`const nsACString& aIdExtension`](https://searchfox.org/mozilla-central/rev/e8da1e780e9b8ed2fd82a3b8d79c5f93e72697d3/netwerk/cache2/CacheEntry.cpp#271) (not sure whether that really is what would be passed for retrieving `partitionKey`).

Edit: I seem to need to get the partitioned cache object like this instead:

```js
let cache_storage = getCacheStorage("disk", Services.loadContextInfo.custom(false, { userContextId: 0, partitionKey: "(https,example.com)" }));
```

Back to Bug 1944310 Comment 8