Want to cache for for logged-in Users
-
hy i have a wordpress the have an restricted access : the site is only accessible for logged-in Users so a want to cache the page and post even if the user is log how can i do that ?
Thanks in advance best simpliest plugin for caching site !
-
With Gator Cache, you can cache pages by user role. However, typically, logged in users would get interactive content that would be broken by a page cache. If this is not the case with your site, you can go to the user tab and choose the role you’d like to cache pages for, eg “Subscribers” and it will cache pages for them. If this is not working for you, it’s probably because an additional role has been added by your membership or forum plugin. Are you using any other plugin to provide membership functionality?
Thanks for the rapid response the thing is :
(i’m a developper)
i have any other cache system on my site and i have made many test with Gator and the result is :– with roles ‘subscibers’ activate (or any others)
the Subscibers (or any others) will have a cached page delivred (if cache exist) but if the cache don’t already exist it don’t create it automaticaly when the subsciber (or any others) browse it..the cache is only and always created by non logged in user
@jibsoux, Yes, this behaviour is by design. Typically a logged in user will get personalized content, such as the admin bar, profile, etc. This is why, by default, Gator Cache does not save the cache for any logged in users.
I really wouldn’t want to make anything like this a setting. However since you’re a developer, I’m thinking about adding a hook where you can override pages not saving the cache for logged in users. I’m also wondering if a cache warmer might be a better solution. Please let me know your thoughts on this.
Ok that what i was thinking !
First : i hate cache warmer, why ? simple :
Your way to manage the cache is way better (logicaly speaking) than cache warmer because for your plugin only when a page or article is updated his cache will be deleted and for only the first user to browse it there is no cache but it create it on the first display and it will be delived for the others users => SO : just 1 user will dont have a caching page, but cache warmer create all the cache periadically only for that 1 user.. for me cache warmer is sooooo useless !—
I understand the thing that logged in users will have there setting like admin bar, profile, etc.. and the basic cache is not applicable for logged in users.
I’m ok for the override it will be to use with precaution by users that understand the risks
and additionnally i found : Fragment Cache capability like that :
https://chrislema.com/high-performance-wordpress-membership-site/
https://www.ads-software.com/plugins/wp-fragment-cache/if we can create a capability for admin of the site to specify where and what they want to cache
or if we can propose some auto setting of that capability it will work for logged in user
@jibsoux, It sounds like you’re looking for a way to basically cache everything but the dynamic content that’s served to a logged in user. In the context of WordPress, the best way I’ve found to do this is to serve dynamic content via ajax. This is probably why WooCommerce populates their cart widget with javascript so it will work and play well with a page cache.
Are you using any certain membership plugin or is this a custom system?
GatorCache can certainly handle fragment caching without a “persistent backend” if you’re looking for an alternative to transients. That sort of API could be readily built into the plugin.
hi yep ajax woud be a solution but i have one site like that theme : https://themes.premitheme.com/?theme=fullscene
you can see the content is already loaded with ajax, the probleme here is the site is accessible only for logged in users.. and i think the capabilities of fragment caching is appropriate don’t you think ?
i use Gator on an other site that have not restricted access so it work great : preuves-par-images.fr / on that site i have a db cache to and a minification + concatenate js & css + deferring the js string so it’s very optimised (you can check the source code) !
—
to respond your question : i don’t have a membership plugin
A new version was just released, 1.56, and contains a way for you to set up generating the cache for logged in users. First, of course, you’d select the role to cache in the Users tab. Then go under the Cache Rules tab and check “Enable hooks” under “Advanced Settings”. Then somewhere in your code, functions.php or another plugin, you can use the gc_cache_user_content hook. Returning a boolean true will cause the cache to generate pages even though the user is logged in. Something like this will work:
add_filter('gc_cache_user_content', function(){return true;});
thank’s when i test it i will make a review ??
by the way there is no charset define in the http head that’s normal ?
++
Little improovement htaccess :<filesMatch “\.(html|gz|ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$”>
Header set Vary “Accept-Encoding, Cookie”
Header set Cache-Control “max-age=5, must-revalidate, public“
</filesMatch>Thanks for suggestions. As far as the cache-control, usually that would only apply to hmtl and gz. The static content, such as css and image files, should probably have a much higher expires.
I just checked out the headers, and yes, you are correct, The typical charset headers and nocache set by WordPress are not being set when served from the cache. So these must happen after advanced-cache.php. There will be an update soon to remedy this. If you’re using http caching this isn’t an issue.
oups yes of course
by the way why do you apply only 5 sec for the max-age ?—
my site i have 1 or 2 updates (new post) by week only, the js and css never change, and can you tell me if that is good setting ?i have the gz in it but with your setting I can delete ii, no ?
## BEGIN EXPIRE HEADERS ExpiresActive On <FilesMatch "\.(ico|jpe?g|png|gif|swf|css|js|gz|html|htm|xml|xhtml)$"> ExpiresDefault "access plus 6 month" </FilesMatch> # FORCE NO CACHING FOR DYNAMIC FILES <FilesMatch "\.(pl|php|cgi|spl|scgi|fcgi)$"> ExpiresActive Off </FilesMatch> ## BEGIN CACHE-CONTROL <filesMatch "\.(ico|jpe?g|png|gif|swf|css|js|gz|html|htm|xml|xhtml)$"> Header set Vary "Accept-Encoding, Cookie" Header set Cache-Control "max-age=15778800, must-revalidate, public" </filesMatch> # FORCE NO CACHING FOR DYNAMIC FILES <FilesMatch "\.(pl|php|cgi|spl|scgi|fcgi)$"> Header unset Cache-Control </FilesMatch>
This is the way I usually set this type of thing up. This would go under the filesMatch html,gz of the cache rules in the “if mod_mime.c block”:
<filesMatch "\.(js)(.*?)$"> Header set Cache-Control "max-age=2592000, public" </filesMatch> <filesMatch "\.(css)(.*?)$"> Header set Cache-Control "max-age=2592000, public" </filesMatch> <filesMatch "\.(ico|jpe?g|png|gif|swf)$"> Header set Cache-Control "max-age=2592000, public" </filesMatch>
Then underneath the Gator Cache block of rules, something like this:
<IfModule mod_expires.c> ExpiresActive On ExpiresByType text/javascript A2592000 ExpiresByType text/css A2592000 ExpiresByType image/x-icon A2592000 ExpiresByType image/jpeg A2592000 ExpiresByType image/png A2592000 ExpiresByType image/gif A2592000 ExpiresByType application/x-font-opentype A31104000 ExpiresByType text/html A3 </IfModule>
The actual content gets a low max age because you typically always want the request to hit the server. WordPress itself sets a max age of 0 in it’s output headers.
Actually, I’ve been experimenting with this a little and yes, you could set a higher expires for your content in the http settings if it isn’t updated that often. However, you’d want to comment out the “Header unset Last-Modified” line in the recommended rules so the Last Modified Header is sent.
one improovement to do : when there is a new post the RSS feed (cached) is not delete..
But it’s work well when i add it to the custom refresh rules
Thanks for the suggestion. Will try to get that in on the next update. It should flush the applicable rss feed when content is added or updated. Maybe have an option whether or not to cache feeds.
- The topic ‘Want to cache for for logged-in Users’ is closed to new replies.