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

tpl: Add "cached" piped option #3417

Closed
bep opened this issue May 1, 2017 · 13 comments
Closed

tpl: Add "cached" piped option #3417

bep opened this issue May 1, 2017 · 13 comments
Assignees
Milestone

Comments

@bep
Copy link
Member

bep commented May 1, 2017

See #3042

The partialCached template func name makes for a bad API.

It would be nice if we could say:

{{ partial "head.html" . | cache }}
{{ partial "head.html" . | cache "some-key" }}

We would keep the old func as an alias, and this keyword would only work for the partial func at the start, but one could imagine we could use it for other things, and maybe add more "options" later.

I guess this would only work for funcs with "vararg room" on the end.

@bep bep self-assigned this May 1, 2017
@bep bep added the Enhancement label May 1, 2017
@bep bep added this to the v0.21 milestone May 1, 2017
@bep
Copy link
Member Author

bep commented May 1, 2017

/cc @moorereason @digitalcraftsman

@digitalcraftsman
Copy link
Member

digitalcraftsman commented May 1, 2017

In other words: the partialCached func could become more generic in the sense that it could also cache / handle more things than just templates in the future, right?

@bep
Copy link
Member Author

bep commented May 1, 2017

No, turn it around: It is the cache keyword that is the generic part (one could imagine partial doing other stuff too, but that is not on my mind in this scenario).

@digitalcraftsman
Copy link
Member

No, turn it around: It is the cache keyword that is the generic part

So, cache becomes the more generic version of partialCached?

@bep
Copy link
Member Author

bep commented May 1, 2017

So, cache becomes the more generic version of partialCached?

Yes. Maybe not relevant for partial, but for, say, images, one could imagine piping several "action options"; image | rotate 30 | flip...?

But even in the partial case, it makes a cleaner API.

@digitalcraftsman
Copy link
Member

images, one could imagine piping several "action options"; image | rotate 30 | flip...?

Do you want to cache a composition of template functions this way?

@bep
Copy link
Member Author

bep commented May 1, 2017

No.

@bep
Copy link
Member Author

bep commented May 1, 2017

And the slightly longer version is:

I would love to come up with a generic "cache func" (how-to-suggestion welcome), but this is just options sent into another func (which can be accumulated).

So both of these are the same:

  • partialCached "head.html"
  • partial | cached

The reason we added the partialCached variant was because func Partial(name string, cached bool) is kind of hard to use and document as a template func. And it becomes even worse if you get func Partial(name string, cached, pretty bool).

Then you may end up with:

  • partialPrettyCached "head.html"

And this breaks down fast if you need some additional and optional cache key etc. So:

  • partial "head.html" | pretty | cached "home-page"

And please don't ask me what pretty is -- I just made it up, but it is a configuration option and not a function doing the work.

@bep bep changed the title tpl: Add "cache" piped option tpl: Add "cached" piped option May 1, 2017
@moorereason
Copy link
Contributor

I agree and understand the reasoning, but the proposed implementation doesn't make sense. With

partial "head.html" . | cached

the partial will always be executed. cached needs to control execution, so the pipe usage would be rare, I think.

@bep
Copy link
Member Author

bep commented May 1, 2017

proposed implementation doesn't make sense.

I haven't proposed an implementation, just the API.

@bep
Copy link
Member Author

bep commented May 1, 2017

But this isn't really important. Let it linger.

@bep bep modified the milestones: v0.22, v0.21 May 9, 2017
@bep bep modified the milestones: v0.22, v0.23 Jun 7, 2017
@bep bep modified the milestones: v0.23, v0.24, v0.25 Jun 16, 2017
@bep bep modified the milestones: v0.111.0, v0.112.0 Feb 15, 2023
@bep bep modified the milestones: v0.112.0, v0.113.0 Apr 15, 2023
@bep bep modified the milestones: v0.113.0, v0.114.0, v0.115.0 Jun 8, 2023
@bep bep modified the milestones: v0.115.0, v0.116.0 Jun 30, 2023
@bep bep modified the milestones: v0.116.0, v0.117.0 Aug 1, 2023
@bep bep modified the milestones: v0.117.0, v0.118.0 Aug 30, 2023
@bep bep modified the milestones: v0.118.0, v0.119.0 Sep 15, 2023
@bep bep modified the milestones: v0.119.0, v0.120.0 Oct 4, 2023
@bep bep modified the milestones: v0.120.0, v0.121.0 Oct 31, 2023
@bep bep modified the milestones: v0.121.0, v0.122.0 Dec 6, 2023
@bep bep modified the milestones: v0.122.0, v0.123.0, v0.124.0 Jan 27, 2024
@bep bep closed this as completed Jan 31, 2024
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants