boldenamsterdam / htmlcache

Cache pages to HTML and boost website performance on Craft CMS 3
MIT License
31 stars 21 forks source link

Only a single template gets cached #4

Closed superflausch closed 5 years ago

superflausch commented 5 years ago

I just tried to implement your plugin but run into an issue.

The plugin only caches the first request/url after I activate it and writes it into a file. Every other site/url I access delivers the initially cached template and not the correct content. No new files get created.

Maybe I setup something wrong. Any ideas what could lead to this behaviour? I still have the default craft cache tags within my templates, not sure if this is recommended/supported.

Cheers.

boldenamsterdam commented 5 years ago

Are the urls different? Do you have an SPA site? Could you check how many files are in the storage/runtime/htmlcache/ folder created? Also, check how many entries are in the table htmlcache_caches in your database created.

Let me know!

superflausch commented 5 years ago

Yes, the urls are different and this is no SPA.

The folder contains just a single file, but I see several entries in the DB with different URIs.

boldenamsterdam commented 5 years ago

Can you try to flush the cache so htmlcache table in db en cache folder are empty? Then try again to access urls and let me know if cache is being created.

superflausch commented 5 years ago

Sorry, it took me so long to get back to you. I hope it's okay to post here in the closed ticket.

I cleared everything like you suggested, even reinstalled the plugin. Unfortunately I still have the same issue. Only the first site template gets stored and every additional request results in the same cached template getting returned. This happens for valid url/entries as well as non existing ones.

I'm getting a single entry int the htmlcache_caches table and multiple in the elements one. I also only getting a single template in the htmlcache runtime folder.

boldenamsterdam commented 5 years ago

Functionality-wise the plugin creates the cache entries based on the uri (GET parameter p) and site id. If you get only one cached template then that means that uri and site id remain the or maybe you use custom routes with the same uri.

Unfortunately I am unable to reproduce your situation. If you could share with me you setup, installation, structure and uri's that are being requested or I might be able to help you.

RyanRoberts commented 5 years ago

I'm having the same problem. I'll install on a fresh site and see if it's happening there too.

perea-truelogic commented 5 years ago

It looks like the plugin doesn't work with friendly urls and relies on the GET parameter p. For example domain.com/path will not get cached but domain.com/path?p=path will work. This is default behavior in line 41 in services/HtmlcacheService.php $this->uri = \Craft::$app->request->getParam('p', ''); What about a PR to make the plugin work with friendly urls, or is the \Craft::$app->request->getParam('p', '') function supposed to get the path if the p param is not present and friendly urls are enabled ?

thisisablock commented 4 years ago

see https://github.com/boldenamsterdam/htmlcache/pull/27