Socket
Socket
Sign inDemoInstall

apollo-cache-inmemory

Package Overview
Dependencies
Maintainers
4
Versions
149
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apollo-cache-inmemory - npm Package Compare versions

Comparing version 1.3.0-beta.11 to 1.3.0-beta.12

7

CHANGELOG.md

@@ -10,2 +10,9 @@ # CHANGELOG

### 1.3.0
- Optimize repeated `apollo-cache-inmemory` reads by caching partial query
results. As a consequence, watched queries will not be rebroadcast unless the
data have changed.
[PR #3394](https://github.com/apollographql/apollo-client/pull/3394)
### 1.2.5

@@ -12,0 +19,0 @@

18

lib/bundle.umd.js

@@ -886,3 +886,3 @@ (function (global, factory) {

}
}
},
});

@@ -908,3 +908,3 @@ return _this;

}
var store = (query.optimistic && this.optimistic.length)
var store = query.optimistic && this.optimistic.length
? defaultNormalizedCacheFactory$1(this.extract(true))

@@ -935,3 +935,3 @@ : this.data;

InMemoryCache.prototype.diff = function (query) {
var store = (query.optimistic && this.optimistic.length)
var store = query.optimistic && this.optimistic.length
? defaultNormalizedCacheFactory$1(this.extract(true))

@@ -1043,4 +1043,11 @@ : this.data;

InMemoryCache.prototype.broadcastWatches = function () {
var _this = this;
if (!this.silenceBroadcast) {
this.watches.forEach(this.maybeBroadcastWatch, this);
var optimistic_1 = this.optimistic.length > 0;
this.watches.forEach(function (c) {
_this.maybeBroadcastWatch(c);
if (optimistic_1) {
_this.maybeBroadcastWatch.dirty(c);
}
});
}

@@ -1056,4 +1063,3 @@ };

});
if (previousResult &&
previousResult === newData.result) {
if (previousResult && previousResult === newData.result) {
return;

@@ -1060,0 +1066,0 @@ }

@@ -30,4 +30,4 @@ var __extends = (this && this.__extends) || (function () {

import { StoreReader } from './readFromStore';
import { defaultNormalizedCacheFactory, DepTrackingCache } from './depTrackingCache';
import { wrap, defaultMakeCacheKey } from "./optimism";
import { defaultNormalizedCacheFactory, DepTrackingCache, } from './depTrackingCache';
import { wrap, defaultMakeCacheKey, } from './optimism';
import { record } from './recordingCache';

@@ -86,3 +86,3 @@ var defaultConfig = {

}
}
},
});

@@ -108,3 +108,3 @@ return _this;

}
var store = (query.optimistic && this.optimistic.length)
var store = query.optimistic && this.optimistic.length
? defaultNormalizedCacheFactory(this.extract(true))

@@ -135,3 +135,3 @@ : this.data;

InMemoryCache.prototype.diff = function (query) {
var store = (query.optimistic && this.optimistic.length)
var store = query.optimistic && this.optimistic.length
? defaultNormalizedCacheFactory(this.extract(true))

@@ -243,4 +243,11 @@ : this.data;

InMemoryCache.prototype.broadcastWatches = function () {
var _this = this;
if (!this.silenceBroadcast) {
this.watches.forEach(this.maybeBroadcastWatch, this);
var optimistic_1 = this.optimistic.length > 0;
this.watches.forEach(function (c) {
_this.maybeBroadcastWatch(c);
if (optimistic_1) {
_this.maybeBroadcastWatch.dirty(c);
}
});
}

@@ -256,4 +263,3 @@ };

});
if (previousResult &&
previousResult === newData.result) {
if (previousResult && previousResult === newData.result) {
return;

@@ -260,0 +266,0 @@ }

{
"name": "apollo-cache-inmemory",
"version": "1.3.0-beta.11",
"version": "1.3.0-beta.12",
"description": "Core abstract of Caching layer for Apollo Client",

@@ -5,0 +5,0 @@ "author": "James Baxley <james@meteor.com>",

@@ -20,4 +20,11 @@ import { DocumentNode } from 'graphql';

import { StoreReader } from './readFromStore';
import { defaultNormalizedCacheFactory, DepTrackingCache } from './depTrackingCache';
import { wrap, defaultMakeCacheKey } from "./optimism";
import {
defaultNormalizedCacheFactory,
DepTrackingCache,
} from './depTrackingCache';
import {
wrap,
defaultMakeCacheKey,
OptimisticWrapperFunction,
} from './optimism';

@@ -82,30 +89,30 @@ import { record } from './recordingCache';

const { maybeBroadcastWatch } = cache;
this.maybeBroadcastWatch = wrap((c: Cache.WatchOptions) => {
return maybeBroadcastWatch.call(this, c);
}, {
makeCacheKey(c: Cache.WatchOptions) {
if (c.optimistic && cache.optimistic.length > 0) {
// If we're reading optimistic data, it doesn't matter if this.data
// is a DepTrackingCache, since it will be ignored.
return;
}
this.maybeBroadcastWatch = wrap(
(c: Cache.WatchOptions) => {
return maybeBroadcastWatch.call(this, c);
},
{
makeCacheKey(c: Cache.WatchOptions) {
if (c.optimistic && cache.optimistic.length > 0) {
// If we're reading optimistic data, it doesn't matter if this.data
// is a DepTrackingCache, since it will be ignored.
return;
}
if (c.previousResult) {
// If a previousResult was provided, assume the caller would prefer
// to compare the previous data to the new data to determine whether
// to broadcast, so we should disable caching by returning here, to
// give maybeBroadcastWatch a chance to do that comparison.
return;
}
if (c.previousResult) {
// If a previousResult was provided, assume the caller would prefer
// to compare the previous data to the new data to determine whether
// to broadcast, so we should disable caching by returning here, to
// give maybeBroadcastWatch a chance to do that comparison.
return;
}
if (cache.data instanceof DepTrackingCache) {
// Return a cache key (thus enabling caching) only if we're currently
// using a data store that can track cache dependencies.
return defaultMakeCacheKey(
c.query,
JSON.stringify(c.variables),
);
}
}
});
if (cache.data instanceof DepTrackingCache) {
// Return a cache key (thus enabling caching) only if we're currently
// using a data store that can track cache dependencies.
return defaultMakeCacheKey(c.query, JSON.stringify(c.variables));
}
},
},
);
}

@@ -132,5 +139,6 @@

const store = (query.optimistic && this.optimistic.length)
? defaultNormalizedCacheFactory(this.extract(true))
: this.data;
const store =
query.optimistic && this.optimistic.length
? defaultNormalizedCacheFactory(this.extract(true))
: this.data;

@@ -163,5 +171,6 @@ return this.storeReader.readQueryFromStore({

public diff<T>(query: Cache.DiffOptions): Cache.DiffResult<T> {
const store = (query.optimistic && this.optimistic.length)
? defaultNormalizedCacheFactory(this.extract(true))
: this.data;
const store =
query.optimistic && this.optimistic.length
? defaultNormalizedCacheFactory(this.extract(true))
: this.data;

@@ -320,3 +329,13 @@ return this.storeReader.diffQueryAgainstStore({

if (!this.silenceBroadcast) {
this.watches.forEach(this.maybeBroadcastWatch, this);
const optimistic = this.optimistic.length > 0;
this.watches.forEach((c: Cache.WatchOptions) => {
this.maybeBroadcastWatch(c);
if (optimistic) {
// If we're broadcasting optimistic data, make sure we rebroadcast
// the real data once we're no longer in an optimistic state.
(this.maybeBroadcastWatch as OptimisticWrapperFunction<
(c: Cache.WatchOptions) => void
>).dirty(c);
}
});
}

@@ -337,4 +356,3 @@ }

if (previousResult &&
previousResult === newData.result) {
if (previousResult && previousResult === newData.result) {
return;

@@ -341,0 +359,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc