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

What's the purpose of the cache in the Resource _construct? #47

Open
danielebriggi opened this issue Aug 1, 2016 · 1 comment
Open
Labels

Comments

@danielebriggi
Copy link
Contributor

danielebriggi commented Aug 1, 2016

I fell in this issue:

  1. I get the main resource
  2. This resource has the included resource A with just the attributes data
  3. Then I fetch-ed the A resources. As result I obtain the list of resources and each of them has the meta data

Debugging, I discovered that the Resource's constructor tries to get itself from caching.
The problem is that in the cache there's the included resource without the meta data (the one obtained within the main resource).

So, what's the purpose of the cache in the constructor of the Resource object?

Maybe the Resource.getUidString() method should be improved.
It should calculate the Uid string using all the fields allowed by the specification in the resource object (attributes, id, type, meta, links etc.)

@theninj4
Copy link
Contributor

The goal is to achieve some level of consistency between resources.

Suppose you have two resources, photos and articles. Suppose you have a photo resource, then you fetch it's article and then pull down all of the photos in that article, you'll now have several photos and one article. You'll also have two instances of the same photo (the one you started with, and the one you got along with all the others from the article). The resourceCache is there to ensure in this scenario you get the same object references. If you have two different parts of your application that are looking at the same resource (by id), then they'll both be sharing the same model, so if one part of the application updates the resource the other part will also see the changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants