Jump to content
hettiger

How to cache pages with GET-Params

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...

Share this post


Link to post
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

Share this post


Link to post
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 :-)

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By jds43
      Hello,
      I have a search page loosely based on Skyscrapers where I'm parsing a selector with options 'beds', 'bathrooms', 'size' fields. It is working well until I select 'Any' after I've run a search. This is where no results are returned (/?beds=&bathrooms=&size=&submit=). I want it to reset and show all results.
      I hope this isn't too vague.
       
    • By verdeandrea
      Hello,
      I am using ProCache v3.1.8 on ProcessWire 3.0.96.
      Everything worked fine in the past, but today I noticed that the css file serverd by procache gives a 410 error. 
      The file is there, I checked.
      I deleted the cached files, I deleted the css file, I looked into the .htaccess file looking for some clues about this problem but nothing worked.
      The only way i can see my website correctly again is disabling ProCache. 
      Has anyone any clue on what could be the cause of the problem or on what should I do to fix it?
      Thanks!
    • By abdulqayyum
      Hy Processwire community,
      There are some problem in fileCompiler cache.
      when i change under the directory \site\templates\ it must change under the directory /site/assets/cache/FileCompiler/site/templates/
      but it does not update and functionality working with /site/assets/cache/FileCompiler/site/templates/ directory.
       
      In this case please suggest me how i clear fileCompiler cache?
      what i have to clear it manually?
      Thanks AbdulQayyum.
    • By brdje
      Greetings,
       
      I've created a product database which all use the template product.php and are published on the website.
      I'm trying to create an overview table with pagination of all the products, but using $pages->get does not return an object, only the object title.
      $products = $pages->get("template=product, limit=10"); This returns 10 strings in the frontend but not the object. When looping over the result set to get product fields, i get the following error:
      Notice: Trying to get property 'title' of non-object
       
      Because the product database is fairly large, i've added a pagination using the same query and this does return all the pages, but i can't click on the links that the paginator renders.
      $results = $pages->find("template=product, limit=10"); if($results->getTotal() > 10) { echo $results->renderPager(array( "nextItemLabel" => "Volgende", "previousItemLabel" => "Vorige", "currentItemClass" => 'active' )); }
      I've added the option in the template to allow page numbers. When i navigate to the link manually, i still end up seeing the 10 first products.
       
      I've tried changing several settings around, but i'm a bit stuck on how to resolve these issues. Do you have any advice what I need to adjust?
      Thanks in advance for your feedback.
       
       
    • By modifiedcontent
      I had upgraded my Apache configuration to include PHP7.2 and PHP7.3 for a Laravel-based script on the same server. Somehow it/I messed up a previously fine Processwire site, in a very confusing way.
      The site still looks fine, but editing template files has no effect whatsoever. It is stuck on some kind of cached version. I have already disabled PHP7's OPcache, cleared browser caches, etc, with no effect.
      The pages now apparently come from PW's assets/cache/FileCompiler folder, even though I never enabled template caching for this site.
      I have tried adding "namespace ProcessWire;" to the top of the homepage template file, but then I get this fatal error:
      My functions.php file pulls data in from another Processwire installation on the same VPS with the following line:
      $othersitedata = new ProcessWire('/home/myaccount/public_html/myothersite/site/', 'https://myothersite.com/'); That apparently still works fine; the site still displays data from the other installation, but via the "cached" template that I am now unable to change.
       
      I don't know where to start with this mess. Does any of this sound familiar to anyone? Any pointers in the right direction would be much appreciated. 
       
      Edit:
      Adding "$config->templateCompile = false;" to config.php results in the same fatal error as above. 
×
×
  • Create New...