Jump to content

How to cache pages with GET-Params


hettiger
 Share

Recommended Posts

Hello there :)

I'll start right away: Let's imagine we have a index page: example.com/recipes
This index page is also a faceted search accepting GET params for search query, categories, tags, ingredients, ...

It would be amazing to be able caching this index page to a certain degree.

For example: 
The GET param categories is somewhat limited. There are only 5 categories in total so it would not add too much overhead.
If I could add this GET param to a whitelist and set the total allowed GET params to 1 for example, this would make a great difference in performance.
(If we consider there are main navigation links pointing to the faceted search with one category preselected)

This would result in cache entries for:

  • example.com/recipes/
  • example.com/recipes/?categories=cooking
  • example.com/recipes/?categories=bbq

While requests like:

  • example.com/recipes/?query=foo
  • example.com/recipes/?categories=cooking&ingredients=cheese

... would not overwork our cache

Is this already possible with core modules? (MarkupCache is not really the answer I'm looking for) Is it possible with Pro Cache?

Of course since it's an index page: We have pagination to consider as well...

Link to comment
Share on other sites

30 minutes ago, hettiger said:

Is this already possible with core modules? (MarkupCache is not really the answer I'm looking for) Is it possible with Pro Cache?

Nope and nope, but caching URL Segments is supported by both ProCache and the (built-in) template cache. Any chance you could replace GET params with URL Segments for this use case?

If that's not an option, I would suggest going with the answer you're not looking for – MarkupCache or WireCache :)

  • Like 3
Link to comment
Share on other sites

19 minutes ago, teppo said:

 

Nope and nope, but ProCache supports caching URL Segments. Any chance you could replace GET params with URL Segments for this use case?

If that's not an option, I would suggest going with the answer you're not looking for – MarkupCache or WireCache :)

Thank you teppo,

URL Segments would be perfectly fine to me. But it breaks once a recipe has the same name as a category. I know it's unlikely in this particular use case but that's just an example and content managers don't care what you explain to them :-/

I hope there is some easier way to solve this problem.

Anyways, I'll try going the URL Segments route using a regex: ^category-[\w-]+$

Seems the best solution to me right now. If anyone's got a better one please let me know :-)

Link to comment
Share on other sites

Just for the record, I updated my post above: Template cache supports caching URL Segments too :)

Anyway, another solution to your issue would be using a structure like /recipes/categories/cooking/, etc. Doesn't really matter whether those categories are URL segments or actual pages, though with pages it would probably be easier to allow your content editors to manage them.

  • Like 1
Link to comment
Share on other sites

11 minutes ago, teppo said:

Just for the record, I updated my post above: Template cache supports caching URL Segments too :)

Anyway, another solution to your issue would be using a structure like /recipes/categories/cooking/, etc. Doesn't really matter whether those categories are URL segments or actual pages, though with pages it would probably be easier to allow your content editors to manage them.

That's brilliant teppo, thank you.

The new regex: ^categories/[\w-]+$

So only a recipe with the name categories could get me into trouble. But that's no big deal.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...