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

it it possible to cache? #19

Open
jjb opened this issue Jul 18, 2014 · 8 comments
Open

it it possible to cache? #19

jjb opened this issue Jul 18, 2014 · 8 comments

Comments

@jjb
Copy link

jjb commented Jul 18, 2014

Do you have any ideas for how to fragement cache the tags metamagic generates?

@lassebunk
Copy link
Owner

Thanks for asking. Can you tell me your use case for it? Thanks.

@jjb
Copy link
Author

jjb commented Jul 18, 2014

i have model Foo

in views/foos/show.html.haml i have

- if @foo.description.present?
  - meta description: @foo.description
  - meta og: {description: @foo.description}

typically i would put such stuff under

- cache @foo

but that doesn't work in this case because meta doesn't generate strings, it adds things to the content_for.

@lassebunk
Copy link
Owner

Could you present an idea on how you'd like to do this? You don't need to
code it, just an example of how you'd use it.

Would you have caching on both the definition and the rendering, or just
the rendering?

Thanks. Lasse

Den fredag den 18. juli 2014 skrev John Bachir [email protected]:

i have model Foo

in views/foos/show.html.haml i have

  • if @foo.description.present?
    • meta description: @foo.description
    • meta og: {description: @foo.description}

typically i would put such stuff under

but that doesn't work in this case because meta doesn't generate strings,
it adds things to the content_for.


Reply to this email directly or view it on GitHub
#19 (comment).

@lassebunk
Copy link
Owner

I think we can do this by adding a helper. I'll think about this.

@jjb
Copy link
Author

jjb commented Jul 18, 2014

i searched around for how others use fragment caching for content_for stuff and it seems to not be done, or possible.

if metamagic wanted to do its own internal system, the user would have to provide a key. so in my case:

- meta description: @foo.description, cache_key: @foo.cache_key
- meta og: {description: @foo.description}, cache_key: @foo.cache_key

and then it uses a combination of the cache key and the thing being cached (og:description etc) as the cache key in the rails cache system.

i don't know how the default values (metamagic vs meta) complicate this. metamagic would have to somehow cache the decision to overwrite, in addition to the content itself.

@lassebunk
Copy link
Owner

I think we could do it something like this:

meta_cache ["v1", @product, @comment] do
  meta title: "My Title",
       description: "Test"
  og image: "image.png"
end

Not sure about the name though. I'll see if we can do something to just use "cache".

This would, in the view, check if the given cache key exists, if not then run the block so the values are set.
The cache key is also sent to the metamagic layout helper, which will then render if needed (if it does not exist in the cache)

Makes sense?

@jjb
Copy link
Author

jjb commented Mar 7, 2015

Hi @lassebunk, sorry for not responding to this!

What you propose indeed looks interesting.

Ideally we could go even further and "flatten" the output into the template's cache. But like I said, I think this would require re-implementing metamagic to not depend on content_for. But I haven't dove into the code to fully explore/confirm this.

Let me know what you think and how much your interest is, and maybe I'll look into it a bit more.

@babgyy
Copy link

babgyy commented Mar 23, 2016

Hi,

Thanks for the nice gem ! It's been working perfectly until I started using caches_action. I can't find any rails way to do this. Neither any metatags gem to help.

Is this still under consideration ?

Or do you have any idea how to do this: have page specific meta tags with caches_action, layout:false enabled ? (posted on SO as well)

Thanks ! Best

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