Skip to content

Commit

Permalink
rename InstanceCache to ResourceManager and move file location:
Browse files Browse the repository at this point in the history
  • Loading branch information
runspired committed Nov 26, 2024
1 parent 8553b77 commit 431523c
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 27 deletions.
2 changes: 1 addition & 1 deletion packages/core-types/src/-private.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ type GlobalKey =
| 'DEBUG_MAP'
| 'IDENTIFIERS'
| 'DOCUMENTS'
// @ember-data/store InstanceCache
// @ember-data/store ResourceManager
| 'CacheForIdentifierCache'
| 'RecordCache'
| 'StoreMap'
Expand Down
4 changes: 2 additions & 2 deletions packages/legacy-compat/src/builders/save-record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @module @ember-data/legacy-compat/builders
*/
import { recordIdentifierFor, storeFor, type StoreRequestInput } from '@ember-data/store';
import type { InstanceCache } from '@ember-data/store/-private';
import type { ResourceManager } from '@ember-data/store/-private';
import { assert } from '@warp-drive/build-config/macros';
import type { StableRecordIdentifier } from '@warp-drive/core-types';
import type { Cache } from '@warp-drive/core-types/cache';
Expand All @@ -26,7 +26,7 @@ function _resourceIsFullDeleted(identifier: StableRecordIdentifier, cache: Cache
return cache.isDeletionCommitted(identifier) || (cache.isNew(identifier) && cache.isDeleted(identifier));
}

function resourceIsFullyDeleted(instanceCache: InstanceCache, identifier: StableRecordIdentifier): boolean {
function resourceIsFullyDeleted(instanceCache: ResourceManager, identifier: StableRecordIdentifier): boolean {
const cache = instanceCache.cache;
return !cache || _resourceIsFullDeleted(identifier, cache);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { createDeferred } from '@ember-data/request';
import type Store from '@ember-data/store';
import type {
FindRecordQuery,
InstanceCache,
Request,
RequestStateService,
ResourceManager,
SaveRecordMutation,
} from '@ember-data/store/-private';
import { coerceId } from '@ember-data/store/-private';
Expand Down Expand Up @@ -285,7 +285,7 @@ export class FetchManager {
}
}

function _isEmpty(instanceCache: InstanceCache, identifier: StableRecordIdentifier): boolean {
function _isEmpty(instanceCache: ResourceManager, identifier: StableRecordIdentifier): boolean {
const cache = instanceCache.cache;
if (!cache) {
return true;
Expand All @@ -297,7 +297,7 @@ function _isEmpty(instanceCache: InstanceCache, identifier: StableRecordIdentifi
return (!isNew || isDeleted) && isEmpty;
}

function _isLoading(cache: InstanceCache, identifier: StableRecordIdentifier): boolean {
function _isLoading(cache: ResourceManager, identifier: StableRecordIdentifier): boolean {
const req = cache.store.getRequestStateService();
// const fulfilled = req.getLastRequestForRecord(identifier);
const isLoaded = cache.recordIsLoaded(identifier);
Expand Down
8 changes: 4 additions & 4 deletions packages/store/src/-private.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

export { Store, storeFor } from './-private/store-service';

export { recordIdentifierFor } from './-private/caches/instance-cache';
export { recordIdentifierFor } from './-private/managers/resource-manager';

export { CacheHandler, type StoreRequestContext } from './-private/cache-handler/handler';
export { type CachePolicy } from './-private/cache-handler/types';
Expand All @@ -14,7 +14,7 @@ export { isStableIdentifier } from './-private/caches/identifier-cache';
export { constructResource } from './-private/utils/construct-resource';

export type { Document } from './-private/document';
export type { InstanceCache } from './-private/caches/instance-cache';
export type { ResourceManager } from './-private/managers/resource-manager';

export type {
FindRecordQuery,
Expand All @@ -41,11 +41,11 @@ export {
export { RecordArrayManager, fastPush } from './-private/managers/record-array-manager';

// leaked for private use / test use, should investigate removing
export { _clearCaches } from './-private/caches/instance-cache';
export { _clearCaches } from './-private/managers/resource-manager';
export { peekCache, removeRecordDataFor } from './-private/caches/cache-utils';

// @ember-data/model needs these temporarily
export { setRecordIdentifier, StoreMap } from './-private/caches/instance-cache';
export { setRecordIdentifier, StoreMap } from './-private/managers/resource-manager';
export { setCacheFor } from './-private/caches/cache-utils';
export { normalizeModelName as _deprecatingNormalize } from './-private/utils/normalize-model-name';
export type { StoreRequestInput } from './-private/cache-handler/handler';
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import type {
} from '@warp-drive/core-types/spec/json-api-raw';

import type { OpaqueRecordInstance } from '../../-types/q/record-instance';
import { CacheForIdentifierCache, removeRecordDataFor, setCacheFor } from '../caches/cache-utils';
import RecordReference from '../legacy-model-support/record-reference';
import { CacheCapabilitiesManager } from '../managers/cache-capabilities-manager';
import type { CacheManager } from '../managers/cache-manager';
import type { CreateRecordProperties, Store } from '../store-service';
import { ensureStringId } from '../utils/coerce-id';
import { CacheForIdentifierCache, removeRecordDataFor, setCacheFor } from './cache-utils';
import { CacheCapabilitiesManager } from './cache-capabilities-manager';
import type { CacheManager } from './cache-manager';

type Destroyable = {
isDestroyed: boolean;
Expand Down Expand Up @@ -106,7 +106,12 @@ type Caches = {
reference: WeakMap<StableRecordIdentifier, RecordReference>;
};

export class InstanceCache {
/**
* The ResourceManager
*
* @internal
*/
export class ResourceManager {
declare store: Store;
declare cache: Cache;
declare _storeWrapper: CacheCapabilitiesManager;
Expand Down Expand Up @@ -207,7 +212,7 @@ export class InstanceCache {

if (LOG_INSTANCE_CACHE) {
// eslint-disable-next-line no-console
console.log(`InstanceCache: created Record for ${String(identifier)}`, properties);
console.log(`ResourceManager: created Record for ${String(identifier)}`, properties);
}
}

Expand Down Expand Up @@ -261,7 +266,7 @@ export class InstanceCache {
this.store._requestCache._clearEntries(identifier);
if (LOG_INSTANCE_CACHE) {
// eslint-disable-next-line no-console
console.log(`InstanceCache: disconnected ${String(identifier)}`);
console.log(`ResourceManager: disconnected ${String(identifier)}`);
}
}

Expand All @@ -278,7 +283,7 @@ export class InstanceCache {
}
if (LOG_INSTANCE_CACHE) {
// eslint-disable-next-line no-console
console.groupCollapsed(`InstanceCache: unloading record for ${String(identifier)}`);
console.groupCollapsed(`ResourceManager: unloading record for ${String(identifier)}`);
}

// TODO is this join still necessary?
Expand All @@ -295,7 +300,7 @@ export class InstanceCache {

if (LOG_INSTANCE_CACHE) {
// eslint-disable-next-line no-console
console.log(`InstanceCache: destroyed record for ${String(identifier)}`);
console.log(`ResourceManager: destroyed record for ${String(identifier)}`);
}
}

Expand All @@ -304,7 +309,7 @@ export class InstanceCache {
removeRecordDataFor(identifier);
if (LOG_INSTANCE_CACHE) {
// eslint-disable-next-line no-console
console.log(`InstanceCache: destroyed cache for ${String(identifier)}`);
console.log(`ResourceManager: destroyed cache for ${String(identifier)}`);
}
} else {
this.disconnect(identifier);
Expand All @@ -313,7 +318,7 @@ export class InstanceCache {
this.store._requestCache._clearEntries(identifier);
if (LOG_INSTANCE_CACHE) {
// eslint-disable-next-line no-console
console.log(`InstanceCache: unloaded RecordData for ${String(identifier)}`);
console.log(`ResourceManager: unloaded RecordData for ${String(identifier)}`);
// eslint-disable-next-line no-console
console.groupEnd();
}
Expand Down Expand Up @@ -372,7 +377,7 @@ export class InstanceCache {

if (LOG_INSTANCE_CACHE) {
// eslint-disable-next-line no-console
console.log(`InstanceCache: updating id to '${id}' for record ${String(identifier)}`);
console.log(`ResourceManager: updating id to '${id}' for record ${String(identifier)}`);
}

const existingIdentifier = this.store.identifierCache.peekRecordIdentifier({ type, id });
Expand All @@ -396,7 +401,7 @@ function _resourceIsFullDeleted(identifier: StableRecordIdentifier, cache: Cache
return cache.isDeletionCommitted(identifier) || (cache.isNew(identifier) && cache.isDeleted(identifier));
}

export function resourceIsFullyDeleted(instanceCache: InstanceCache, identifier: StableRecordIdentifier): boolean {
export function resourceIsFullyDeleted(instanceCache: ResourceManager, identifier: StableRecordIdentifier): boolean {
const cache = instanceCache.cache;
return !cache || _resourceIsFullDeleted(identifier, cache);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import type { Links, PaginationLinks } from '@warp-drive/core-types/spec/json-ap

import type { OpaqueRecordInstance } from '../../-types/q/record-instance';
import { isStableIdentifier } from '../caches/identifier-cache';
import { recordIdentifierFor } from '../caches/instance-cache';
import { recordIdentifierFor } from '../managers/resource-manager';
import type { RecordArrayManager } from '../managers/record-array-manager';
import type { Store } from '../store-service';
import { NativeProxy } from './native-proxy-type-fix';
Expand Down
8 changes: 4 additions & 4 deletions packages/store/src/-private/store-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ import type { StoreRequestInput } from './cache-handler/handler';
import type { CachePolicy } from './cache-handler/types';
import { IdentifierCache } from './caches/identifier-cache';
import {
InstanceCache,
ResourceManager,
peekRecordIdentifier,
preloadData,
recordIdentifierFor,
resourceIsFullyDeleted,
storeFor,
} from './caches/instance-cache';
} from './managers/resource-manager';
import type { Document } from './document';
import type RecordReference from './legacy-model-support/record-reference';
import { getShimClass } from './legacy-model-support/shim-model-class';
Expand Down Expand Up @@ -534,7 +534,7 @@ export class Store extends BaseClass {
// Private
declare _graph?: Graph;
declare _requestCache: RequestStateService;
declare _instanceCache: InstanceCache;
declare _instanceCache: ResourceManager;
declare _documentCache: Map<
StableDocumentIdentifier,
Document<OpaqueRecordInstance | OpaqueRecordInstance[] | null | undefined>
Expand Down Expand Up @@ -590,7 +590,7 @@ export class Store extends BaseClass {

// private
this._requestCache = new RequestStateService(this);
this._instanceCache = new InstanceCache(this);
this._instanceCache = new ResourceManager(this);
this._documentCache = new Map();

this.isDestroying = false;
Expand Down

0 comments on commit 431523c

Please sign in to comment.