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

Cache key for extended templates #391

Open
chancancode opened this issue Jan 20, 2013 · 3 comments
Open

Cache key for extended templates #391

chancancode opened this issue Jan 20, 2013 · 3 comments

Comments

@chancancode
Copy link

The documentation seems to suggest that I can do this:

In topics/index.json.rabl:

collection @topics
extends 'topics/base'

In topics/base.json.rabl:

object @topic
cache ['v1', @topic]
attribute :id

Actual result:

[
  { "topic": {"id": 1} },
  { "topic": {"id": 1} },
  { "topic": {"id": 1} },
  { "topic": {"id": 1} },
  { "topic": {"id": 1} },
  ...
]

The reason is that when topics/base is being extended in topics/index, @topic inside topics/base is not set correctly (it is nil, not sure if it's by design).

Therefore, when Rabl try to generate a cache key from ['v1', @topic], it ends up generating one from ['v1', nil], and hence the result from the first object is being reused for all the @topics.

This seems to work, but it's probably considered a hack:

In topics/base.json.rabl:

object @topic
cache ['v1', @_data_object]
attribute :id
@nesquena
Copy link
Owner

Any thoughts @databyte ?

@DarrenFung
Copy link

In the base object, can't you just use ['v1', root_object]?

@chancancode
Copy link
Author

Right, I don't see why @DKFUNG's solution won't work, as root_object simply returns @_data_object. I think I was just a little confused by the documentation when I first got started. Upon re-examining the documentation, it does in fact cover root_object in the last example.

However, the first collection example simply users cache @user, and based on my description in the ticket, that seems to be incorrect? I can't verify this for the moment, so if someone can whip up a simple test case for this it'd be nice (otherwise I'll get to it when I have time).

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

3 participants