2

I've read documentation and it says, that We shouldn't use cache tags on static text.

I have a files, that are static in that way, that the data are pulled from within a file, or in some case, data are pulled from outside a file, where cache tags are.

For example - language and territory data, static navigation.

Within cache tags I have pretty computationally statements and looping, where documentation says, that it's exception.

3

The reason the documentation says to not use it on static text, is because the cached data will be saved to the database, resulting in at least one database query (two if it needs to update the data). Database operations are fairly expensive compared to reading data from files, or running twig code, so in many cases this will be slower than just showing the text.

There's no way to know for sure if using cache tags will be a benefit in your case. It really depends on what exactly you're doing in your template, and where the bottlenecks in your system is. The only way to know, is to test it. If you turn devMode on, reload your page with and without the cache tag enabled, you could compare the response time shown in the console output under "Profiling Summary Report". This is the time it takes for the page to be generated by craft, which is what you'd seek to minimize using the cache tag. Remember to reload the page several times for each case and do an average, since the result will vary somewhat depending on what else is going on in your system.

| improve this answer | |
  • Yes, indeed. The test showed up, that using cache tags on data pulled from within the file, has increased the size of transferred data from server. So What I've learned, is to use cache tags on parts of code, where database queries is performed only. – Dominik Krulak Apr 6 '15 at 10:21
  • 1
    @Dominik ...and/or if you do anything which is computationally really taxing in your template, such as looping through a serious number of objects, merging large arrays within loops, complex string manipulations etc. Like André says, when in doubt check your profiling :) – Mats Mikkel Rummelhoff Apr 6 '15 at 19:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.