E
E
eugene1592020-02-23 23:44:45
MODX
eugene159, 2020-02-23 23:44:45

How do you know when to call your snippet cached and when not cached?

There are snippets that MUST be called uncached (with an exclamation mark at the beginning). AjaxForm, for example, or pdoPage. What about your snippets? When should I call my snippet cached and when not? Or does it matter here? I after all caching any did not write.

pdoResources returns a new result each time. Because the resources are different. And placeholders will have different values. Why is it called cached (no exclamation mark)? This can be seen on the documentation page in the examples:
https://docs.modx.pro/en/components/pdotools/snipp...

But pdoPage is not cached (with an exclamation mark):
https://docs.modx.pro/komponentyi/ pdotools/snippet...

I don't see the logic by which I could understand how I should call my snippets.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Tarasov, 2020-02-24
@an-tar

pdoResources returns a new result each time.

I would say that other things being equal, it returns exactly the same result sooner and more often, which is why it can be cached. Well, or it is highly desirable for a well-known reason - saving a resource.
Or another example from the pdoTools collection - pdoMenu. The menu can be complex (for example, a la megamenu), but change extremely rarely (you have made the site structure once and use it), so it is obviously extremely beneficial to have it cached. If something in the structure (or the resources themselves) changes, MODX itself re-caches the call.
Or another example of pdoSitemap - if the sitemap changes, it doesn’t change often, and it can also require significant resources to generate, so the call here needs to be cached, but if something changes in the structure, the kernel will take care of it.
Cached ones are needed where every time there is new data - ajax requests / responses, pagination, or several similar calls on the page or such nesting of the call that, due to the internal non-cached one, the outer one will also not be cached ... and as a result, both are not cached ....hence AjaxForm, pdoPage, etc.
If your snippet will produce something new every time, don't cache it, otherwise cache it. The principle as a whole is the same as I wrote above, but sometimes there are nuances .. for example, when you would like to cache, but you can’t. Or you can, but you need to write your own caching mechanism.
It was your captain

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question