Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Themes & Styling

Caching implications for nicetime twig function

Started by Robert 7 years ago · 2 replies · 452 views
7 years ago

I found and like the twig function nicetime to be used with my blog item template.

https://learn.getgrav.org/themes/twig-filters-functions#nice-time

However, I guess that since this value needs to be evaluated on every page request (since it changes from "1 minute ago" to "1 hour ago" to "1 day ago" etc.) it will have impact on caching.

My assumption is that any page that uses this function is actually never cached because of this.

Can anyone explain the caching implications / penalties for using this function? Can I safely use it or should I avoid it?

7 years ago

@metbril As far as I know, 'nicetime' will not have any impact on caching.

Grav does not cache the resulting HTML file, which will indeed change over time. Instead, Grav caches the php file generated when compiling a Twig template.

Try the following:

  • Search for 'nicetime' in the cache folder.
    This will only return a cached PHP file generated by Twig compilation.
  • Search for the current result of 'nicetime' (e.g. '5 days ago') in the cache folder.
    You won't find it...
7 years ago

I will do this when I have access to the filesystem and can do a 'grep'.

Suggested topics

Topic Participants Replies Views Activity
Themes & Styling · by Pedro M, 2 months ago
4 197 2 months ago
Themes & Styling · by Ian, 2 months ago
3 92 2 months ago
Themes & Styling · by Norbert, 2 years ago
11 454 3 months ago
Themes & Styling · by Lukáš Findeis, 3 months ago
0 47 3 months ago
Themes & Styling · by Sebadamus, 4 months ago
5 127 3 months ago