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

New Cache strategy: Only cache the attributes of AMS #547

Closed
wants to merge 4 commits into from

Conversation

zlx
Copy link

@zlx zlx commented Apr 16, 2014

New Cache Strategy: Only cache the attributes of AMS

I think It's better to manage attributes only for AMS.

example:

imagine we have an AMS A, which contain AMS B, which contain AMS C.

If I fetch json from A, 
It will read A's attributes cache + B's result
B's result = B's attributes cache + C's result
C's result = C's attribute cache

therefore, it can manage cache by itself object and reusing the cache as far as possible

If B's cache expired, C's cache and A's cache is still work, it will lead to as little computation as possible

Beside, It will detect the AMS class's change and automatic expired the cache.

@GetContented
Copy link

Pretty keen for caching to come back. Also, recursive relationships (Item has_many: items) breaks/broke caching. Should I create a new issue for this? Seems silly when the caching has been taken out.

@zlx
Copy link
Author

zlx commented Apr 26, 2014

@JulianLeviston It's so bad for recursive relationships. I never discover this case in my product. Can you give an example in real situation?

@GetContented
Copy link

@zlx Not sure what you mean by "it" when you say "it's so bad for recursive relationships".

However, my application has exactly such a recursive relationship... I have a model called Item that has a parent, which is also an Item. (In other words, it's a tree of objects). This is my real application, and it's a real situation. All I want to do is cache a JSON render. I'm not doing any embedding, just caching primary keys. There are no loops... (ie the root parent item is not referred to in any of the subsequent item children) and yet the library loops infinitely for some reason when asked to cache it.

The object trees that I have in my app are probably at most like 10 objects deep in terms of parent/children, and all I want to do is get "all the items", flat, with their referring primary keys (ie their parent_id records).

I'd reckon your PR would address this issue, no?

@zlx
Copy link
Author

zlx commented Apr 26, 2014

@JulianLeviston In my understanding, you have situation like below:

A = A's attrs + A1
A1 = A1's attrs + A2
...

An is a A object

for this new cache strategy, I only use cache to replace all the object's attrs, so it will work I think.

But in your situation with so deep relations, I think cache global is more efficiently. consider cache the whole object like use jbuilder to cache AMS or use perforated to cache AMS.

I want to use this PR to make the cache can work efficiently as far as possible when some object changed, because it's the mostly use case I think.

@GetContented
Copy link

@zlx I'm not sure. Thanks tho :)

@steveklabnik
Copy link
Contributor

I'm not currently interested in adding huge new features to 0.9, sorry! We will certainly bring caching back in 0.10.

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

Successfully merging this pull request may close these issues.

4 participants