What is cache policy?

1.59K viewsWordPress

What is cache policy?

Can someone explain this image?

Suraif Ahamed Answered question December 22, 2021
1

As you know, the cache is temporarily storing the content from the previous requests. Also, the Cache TTL is the time that an object will be stored in a caching system before it’s deleted or refreshed. So, the cache policy means the rules and regulations for it (Ex: TTL time for CSS file).

We can set those times on our .htaceess file. This process is called Leverage Browser Caching.

Examples for Leverage browser cache code.
# Leverage Browser Caching
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg “access 1 year”
ExpiresByType image/jpeg “access 1 year”
ExpiresByType image/gif “access 1 year”
ExpiresByType image/png “access 1 year”
ExpiresByType text/css “access 1 month”
ExpiresByType text/html “access 1 month”
ExpiresByType application/pdf “access 1 month”
ExpiresByType text/x-javascript “access 1 month”
ExpiresByType application/x-shockwave-flash “access 1 month”
ExpiresByType image/x-icon “access 1 year”
ExpiresDefault “access 1 month”
</IfModule>

In the screenshot, it seems all are CDN requests.
So you can use these codes.

If you want to use Leverage browser caching for CDN, it’s good to cache files by adding some caching headers like Cache-Control, Expires, and Last-Modified.

# Leverage browser caching using mod_headers #
<IfModule mod_headers.c>
<FilesMatch “\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$”>
Header set Expires “Wed, 15 Apr 2020 20:00:00 GMT”
Header set Cache-Control “public”
</FilesMatch>
</IfModule>
# End of Leverage browser caching using mod_headers #

below examples are for testing:

# 1 YEAR
<FilesMatch “\.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav)$”>
Header set Cache-Control “max-age=31536000, public”
</FilesMatch>

# 1 WEEK
<FilesMatch “\.(jpg|jpeg|png|gif|swf)$”>
Header set Cache-Control “max-age=604800, public”
</FilesMatch>

# 3 HOUR
<FilesMatch “\.(txt|xml|js|css)$”>
Header set Cache-Control “max-age=10800”
</FilesMatch>

# NEVER CACHE – notice the extra directives
<FilesMatch “\.(html|htm|php|cgi|pl)$”>
Header set Cache-Control “max-age=0, private, no-store, no-cache, must-revalidate”
</FilesMatch>

In WordPress, we can use the following plugins.
Litespeed LScache plugin
Wp Rocket

Suraif Ahamed Answered question December 22, 2021
3