Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 68 additions & 64 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
3.3.2 (Dan Reynolds)
3.3.3 (Dan Reynolds)

- Test against latest Apollo, add entity renewal test.

3.3.2 (Dan Reynolds)

Fixes bug where query responses without a typename are never evicted.

Expand Down Expand Up @@ -80,125 +84,125 @@ Reinitialize all invalidation policy objects after cache init()

2.3.0 (Dan Reynolds)

* Update TSConfig
- Update TSConfig

2.2.0 (Dan Reynolds)
2.2.0 (Dan Reynolds)

* Revert lodash-es change and use module imports instead
- Revert lodash-es change and use module imports instead

2.1.0 (Dan Reynolds)
2.1.0 (Dan Reynolds)

* Switch from using lodash to lodash-es to reduce bundle size
- Switch from using lodash to lodash-es to reduce bundle size

2.0.3 (Dan Reynolds)
2.0.3 (Dan Reynolds)

* Filter out dangling references from collection entities
- Filter out dangling references from collection entities

2.0.2 (Dan Reynolds)
2.0.2 (Dan Reynolds)

* Fix a bug with evicting expired fields with a field alias
- Fix a bug with evicting expired fields with a field alias

2.0.1 (Dan Reynolds)
2.0.1 (Dan Reynolds)

* Fix issue with custom Query type keyArgs preventing TTLs from evicting entities
- Fix issue with custom Query type keyArgs preventing TTLs from evicting entities

2.0.0 (Dan Reynolds)
2.0.0 (Dan Reynolds)

* [Breaking] Updates to useFragment/useFragmentWhere APIs. Changes how it works internally to base fragment field policy names off dynamic UUIDs instead of the name of the fragment. Now Returns the data directly on the result as opposed to nested within the field name.
* Adds support for a default function syntax for invalidation policy events.
- [Breaking] Updates to useFragment/useFragmentWhere APIs. Changes how it works internally to base fragment field policy names off dynamic UUIDs instead of the name of the fragment. Now Returns the data directly on the result as opposed to nested within the field name.
- Adds support for a default function syntax for invalidation policy events.

1.5.0 (Dan Reynolds)
1.5.0 (Dan Reynolds)

- Add `evictWhere` API for evicting entities by a filter
* Add `evictWhere` API for evicting entities by a filter

1.4.0 (Dan Reynolds)
1.4.0 (Dan Reynolds)

- Support Apollo 3.4 `init` API to reset the entity type map and watcher.
* Support Apollo 3.4 `init` API to reset the entity type map and watcher.

1.3.0 (Dan Reynolds)
1.3.0 (Dan Reynolds)

- Adds experimental normalized collections
* Adds experimental normalized collections

1.2.2 (Dan Reynolds)
1.2.2 (Dan Reynolds)

- Expose args field on policy action meta objects
* Expose args field on policy action meta objects

1.2.1 (Dan Reynolds)
1.2.1 (Dan Reynolds)

- Publish publicly. Sorry OSS friends!
* Publish publicly. Sorry OSS friends!

1.2.0 (Dan Reynolds)
1.2.0 (Dan Reynolds)

- Update to TypeScript ^4.0
* Update to TypeScript ^4.0

1.1.0 (Dan Reynolds)
1.1.0 (Dan Reynolds)

- Rename library to Apollo Cache Policies and release under the NerdWallet org at `@nerdwallet/apollo-cache-policies`
* Rename library to Apollo Cache Policies and release under the NerdWallet org at `@nerdwallet/apollo-cache-policies`

1.0.0-beta16 (Dan Reynolds)
1.0.0-beta16 (Dan Reynolds)

- Release new version with React dependencies removed.
* Release new version with React dependencies removed.

1.0.0-beta15 (Dan Reynolds)
1.0.0-beta15 (Dan Reynolds)

- Fix bug where a renew-on-read policy would try to update the cache time for entities not present in the cache
* Fix bug where a renew-on-read policy would try to update the cache time for entities not present in the cache

1.0.0-beta14 (Dan Reynolds)
1.0.0-beta14 (Dan Reynolds)

- Bugfix for fixing eviction/mutation changes to the cache via the wrapper `wrapDestructiveCacheMethod` function.
* Bugfix for fixing eviction/mutation changes to the cache via the wrapper `wrapDestructiveCacheMethod` function.

1.0.0-beta13 (Dan Reynolds)
1.0.0-beta13 (Dan Reynolds)

- Short-term fix that adds support for running the lib in environments that cannot handle import statements by removing imports from non-public Apollo APIs.
The required imports will be made available in an upcoming version of Apollo Client and we'll switch to that better fix at that time.
* Short-term fix that adds support for running the lib in environments that cannot handle import statements by removing imports from non-public Apollo APIs.
The required imports will be made available in an upcoming version of Apollo Client and we'll switch to that better fix at that time.

1.0.0-beta12 (Dan Reynolds)
1.0.0-beta12 (Dan Reynolds)

- Add support for dynamically activating/deactivating policy events
* Add support for dynamically activating/deactivating policy events

1.0.0-beta11 (Dan Reynolds)
1.0.0-beta11 (Dan Reynolds)

- Default the `readPolicy` function in the policy action to use the ROOT_QUERY similarly to how the policies module does in apollo/client
* Default the `readPolicy` function in the policy action to use the ROOT_QUERY similarly to how the policies module does in apollo/client

1.0.0-beta10 (Dan Reynolds)
1.0.0-beta10 (Dan Reynolds)

- Add support for a default policy action to perform side effects whenever a specific type is written/evicted from the cache
* Add support for a default policy action to perform side effects whenever a specific type is written/evicted from the cache

1.0.0-beta9 (Dan Reynolds)
1.0.0-beta9 (Dan Reynolds)

- Add `expiredEntities` API for accessing the expired entities in the cache without evicting them
* Add `expiredEntities` API for accessing the expired entities in the cache without evicting them

1.0.0-beta8 (Dan Reynolds)
1.0.0-beta8 (Dan Reynolds)

- Add test for Write-on-Write policies where the mutation has arguments and fix the Readme to illustrate how to correctly write the invalidation policy in that case
* Add test for Write-on-Write policies where the mutation has arguments and fix the Readme to illustrate how to correctly write the invalidation policy in that case

1.0.0-beta7 (Dan Reynolds)
1.0.0-beta7 (Dan Reynolds)

- Fix issue where read policies were attempted to be evaluated for non-normalized entities not yet in the cache if they had a different store field name with the same name
* Fix issue where read policies were attempted to be evaluated for non-normalized entities not yet in the cache if they had a different store field name with the same name
already written in the cache.

1.0.0-beta6 (Dan Reynolds)
1.0.0-beta6 (Dan Reynolds)

- Adds a `storage` dictionary by unique `storeFieldName` for queries or `ID` for normalized entities in the policy action object so that arbitrary meta information can be stored across multiple policy action invocations.
* Adds a `storage` dictionary by unique `storeFieldName` for queries or `ID` for normalized entities in the policy action object so that arbitrary meta information can be stored across multiple policy action invocations.

1.0.0-beta5 (Dan Reynolds)
1.0.0-beta5 (Dan Reynolds)

- Adds support for a `renewalPolicy` type and global config option for specifying how type TTLs should be renewed on write vs access
- Adds the `expire` API for evicting all entities that have expired in the cache based on their type's or the global TTL.
* Adds support for a `renewalPolicy` type and global config option for specifying how type TTLs should be renewed on write vs access
* Adds the `expire` API for evicting all entities that have expired in the cache based on their type's or the global TTL.

1.0.0-beta4 (Dan Reynolds)
1.0.0-beta4 (Dan Reynolds)

- [BREAKING CHANGE] Adds support for a default TTL option that applies to all types
* [BREAKING CHANGE] Adds support for a default TTL option that applies to all types

1.0.0-beta3 (Dan Reynolds)
1.0.0-beta3 (Dan Reynolds)

- Ensure that empty field arguments are still passed as an empty object as the variables in the policy event.
* Ensure that empty field arguments are still passed as an empty object as the variables in the policy event.

1.0.0-beta2 (Dan Reynolds)
1.0.0-beta2 (Dan Reynolds)

- Bumps to latest Apollo version (3.1)
- Adds audit logging for better entity debugging through the type map and invalidation policy manager
* Bumps to latest Apollo version (3.1)
* Adds audit logging for better entity debugging through the type map and invalidation policy manager

1.0.0-beta1 (Dan Reynolds)
1.0.0-beta1 (Dan Reynolds)

- Initial beta release 🚀
* Initial beta release 🚀
30 changes: 15 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nerdwallet/apollo-cache-policies",
"version": "3.3.2",
"version": "3.3.3",
"description": "An extension to the InMemoryCache from Apollo that adds additional cache policies.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
29 changes: 18 additions & 11 deletions src/cache/ReactiveVarsCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import { InvalidationPolicyCache } from ".";

var rvCache!: ReactiveVarsCache;

export const cachedReactiveVarTypename = 'CachedReactiveVar';
export const cachedReactiveVarTypename = "CachedReactiveVar";

export function initReactiveVarsCache(cache: InvalidationPolicyCache): ReactiveVarsCache {
export function initReactiveVarsCache(
cache: InvalidationPolicyCache
): ReactiveVarsCache {
rvCache = new ReactiveVarsCache({
cache,
});
Expand All @@ -17,7 +19,7 @@ const cachedReactiveVarFragment = gql`
id
value
}
`
`;

export function makeCachedVar<T>(id: string, value: T): ReactiveVar<T> {
return rvCache.registerCachedVar<T>(id, value);
Expand All @@ -28,10 +30,13 @@ interface ReactiveVarsCacheConfig {
}

export class ReactiveVarsCache {
registeredVars: Record<string, {
rv: ReactiveVar<any>;
defaultValue: any;
}> = {};
registeredVars: Record<
string,
{
rv: ReactiveVar<any>;
defaultValue: any;
}
> = {};
cache!: InvalidationPolicyCache;

constructor({ cache }: ReactiveVarsCacheConfig) {
Expand All @@ -40,7 +45,7 @@ export class ReactiveVarsCache {

private watchReactiveVar<T>(id: string, rv: ReactiveVar<T>) {
rv.onNextChange((value) => {
this.writeCachedVar(id, value)
this.writeCachedVar(id, value);
// Reactive variables support an `onNextChange` API that allows listeners
// to subscribe to the next value change. This only applies to a single change,
// so to subscribe to every change, a new listener must be added after processing
Expand All @@ -54,13 +59,15 @@ export class ReactiveVarsCache {
const rv = makeVar<T>(cachedValue ?? defaultValue);

if (this.registeredVars[id]) {
console.warn(`Duplicate cached reactive variable with ID ${id} detected. Multiple cached reactive variables should not share the same ID.`);
console.warn(
`Duplicate cached reactive variable with ID ${id} detected. Multiple cached reactive variables should not share the same ID.`
);
}

this.registeredVars[id] = {
rv,
defaultValue,
}
};

// If the cache did not already had a value for the CachedReactiveVar with this ID,
// then it should be seeded with one using the provided default value.
Expand Down Expand Up @@ -97,7 +104,7 @@ export class ReactiveVarsCache {
__typename: cachedReactiveVarTypename,
id,
value,
}
},
});
}
}
Expand Down
Loading