Move Module Cache outside of resource#696
Conversation
f247fa6 to
b881e2d
Compare
| } | ||
|
|
||
| let response = await this.loaderService.loader.fetch(fileURL, { | ||
| headers: { Accept: SupportedMimeType.CardSource }, |
There was a problem hiding this comment.
It seems that this was not the issue breaking test altho I thought it was at one point so I just reverted here
There was a problem hiding this comment.
this seems like a bad assumption. how do you know that URL that is being requested is for card-source? This service is called "realm-info-service" it doesn't seem to indicate that this is only for card sources. Perhaps the accept header should be part of the parameters if this is necessary
There was a problem hiding this comment.
if I were to use the realmInfo provider, I'd need to do a fetch for card source. I can use a different method and a different cache so we will not make this bad assumption. But the method that is called fetchExtension can be used for CardSource
There was a problem hiding this comment.
having these implicit requirements on the callers feels like it could be the source of bugs if people don't clearly understand how to use this API. I would suggest that just make the accept header explicit by requiring callers to specify it when they provide the URL to get the realm info. the accept header is part of how you ask for resources from the realm server anyways--let's just make that clear in our API for this service
|
|
||
| import LoaderService from '@cardstack/host/services/loader-service'; | ||
|
|
||
| export default class ModuleInfoService extends Service { |
There was a problem hiding this comment.
I don't understand why you need this service--isn't this what realm info service is doing? why can't you just move the cache into that service?
There was a problem hiding this comment.
I am fine with that. I considered that initially because the things it does is so similar to the realmInfoProvider but just felt that the naming purpose wasnt quite right. I can go ahead with that -- it does reduce code and caches
There was a problem hiding this comment.
is this to cache 302 redirects? seems like a premature optimization to me. Until we know that is a real issue i would suggest that we should eliminate these lines of code.
| let response = await this.loaderService.loader.fetch(moduleIdentifier, { | ||
| headers: { Accept: SupportedMimeType.CardSource }, | ||
| }); | ||
| let realmURL = response.headers.get('x-boxel-realm-url'); |
There was a problem hiding this comment.
let's not reinvent the wheel and use the realm-info service here
|
just to be clear, my comment around module scope did not mean move this into a service. It simply meant move the cache one block higher in the scope of the resource you already had (supeer simple change), so that instead of having: export class CardType extends Resource<Args> {
moduleMetaCache: Map<string, { extension: string; realmInfo: RealmInfo }> = new Map();
}you would have: const moduleMetaCache: Map<string, { extension: string; realmInfo: RealmInfo }> = new Map();
export class CardType extends Resource<Args> {
...
}that way the cache is shared by all instances of the card type resource instead of only within a single instance. but i can see that if you want the cache to be shared by things that are not CardType resources, then caching in a service makes sense. but given what actually consumes this, i think making this a service is premature at this point |
d80dd41 to
c9c9252
Compare
Ok I have made a change based upon this ultimately just moving the cache into module scope. I didn't use the realm info service and didn't create another service |
habdelra
left a comment
There was a problem hiding this comment.
nice. very tight (low LOC) 👍
This PR moves cache into service rather than residing in the resource
The original motive of this is so that other resources can consume this if needed. Here is the comment #656 (comment)