Inside getOrCreateResource, the following is called:
public getOrCreateResource(id: string): R {
let service = Converter.getServiceOrFail(this.type);
let resource: R;
resource = <R>CacheMemory.getInstance().getResource(this.type, id);
if (resource === null) {
resource = <R>service.new();
resource.id = id;
CacheMemory.getInstance().setResource(resource, false);
}
if (resource.source !== 'new') {
resource.source = 'memory';
}
return resource;
}
The Problem
On the first invocation of Service.all(paramsCollection), it doesn't find anything, but it then always caches every returned resource.
On each subsequent invocation of .all the CacheMemory will have the resource and return the cached resource.
I have fixed this by extending the Resource service and overriding getOrCreateResource and createResource to remove the CacheMemory logic.
Issue
I've disabled caching:
When I make a query like so:
The
Service.getAllFromServer
handles the response with this stack:Inside getOrCreateResource, the following is called:
The Problem
On the first invocation of
Service.all(paramsCollection)
, it doesn't find anything, but it then always caches every returned resource. On each subsequent invocation of.all
the CacheMemory will have the resource and return the cached resource. I have fixed this by extending theResource
service and overridinggetOrCreateResource
andcreateResource
to remove the CacheMemory logic.Suggested Solution
The CacheMemory code in
Service.ts
getOrCreateResource
andService.ts
createResource
needs a similarcachestore_support
check, like this commit has: https://github.com/reyesoft/ngx-jsonapi/commit/5b964f9ee7af8cd8391f066fc9247362a8bdf213https://github.com/reyesoft/ngx-jsonapi/blob/v2.1/src/service.ts#L369