Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cachestore_support false does not disable caching of .all query resources #282

Open
agenaille opened this issue Aug 11, 2020 · 0 comments
Open

Comments

@agenaille
Copy link

agenaille commented Aug 11, 2020

Issue

I've disabled caching:

NgxJsonapiModule.forRoot({
    url: '/api/',
    cache_prerequests: false,
    cachestore_support: false
})

When I make a query like so:

service.all(paramsCollection);

The Service.getAllFromServer handles the response with this stack:

node_modules/ngx-jsonapi/ngx-jsonapi/@ngx-jsonapi/ngx-jsonapi.es5.js.Service.getOrCreateResource
node_modules/ngx-jsonapi/ngx-jsonapi/@ngx-jsonapi/ngx-jsonapi.es5.js.RelatedDocumentCollection.getResourceOrFail (ngx-jsonapi.es5.js:942)
node_modules/ngx-jsonapi/ngx-jsonapi/@ngx-jsonapi/ngx-jsonapi.es5.js.RelatedDocumentCollection.fill (ngx-jsonapi.es5.js:891)
....
....
....
node_modules/ngx-jsonapi/ngx-jsonapi/@ngx-jsonapi/ngx-jsonapi.es5.js.Service.getAllFromServer (ngx-jsonapi.es5.js:3209)

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.

Suggested Solution

The CacheMemory code in Service.ts getOrCreateResource and Service.ts createResource needs a similar cachestore_support check, like this commit has: 5b964f9

https://github.com/reyesoft/ngx-jsonapi/blob/v2.1/src/service.ts#L369

if (Core.injectedServices.rsJsonapiConfig.cachestore_support) {
    // do the caching
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant