Monday 9 March 2020

How To: Wordpress and PHP App Cache Clearing Solution


Wordpress & PHP Cache-Control Solution


How to Handle Memory Cache-Control in Wordpress and PHP Applications (Cache Clearing)



Usefulness of Caching

Using caching on your website is possibly the most effective way to decrease loading times of your web pages and bring content to your visitors quickly.

Wordpress Cache Plugins

  • WP Super Cache
  • W3 Total Cache
  • WP-Optimize (Clean, Compress, Cache)

Other performances improvement plugin

  • a3 Lazy Load
  • Accelerated Mobile Pages
In general, you can cache a variety of aspects of your WordPress website:
  • Menu Cache: Cache your WordPress navigation menus.
  • NIX Gravatar Cache: Easily cache your Gravatar images.
  • Cache External Scripts: Plugin to cache your external scripts.
  • Widget Output Cache: Cache all widget content.

Problems with Caching

As a developer of PHP or Wordpress, while in the process of developing your application or content, you will be faced with memory caching problems.

The automatic memory caching configurations will prevent your PHP or WP application form showing the most current content outputs that should be produced by changes in your script codebase.

Clearing your Plugin Cache

Not being able to view the recent post or page changes or being unable to view changes made using the customizer, are some of the most common cache issues users can experience when making use of a cache plugin.

Most cache issues can be solved by clearing the cache. That can usually be done via the provided options page of the cache plugin you're currently using on your Wordpress website.

The Solution to Solving Memory Cache Problem in Wordpress and PHP Applications

There are multiple approaches to solving the application memory caching drawbacks.

I will try to arrange according to hierarchy, so you know which ones come first.
  • Clearing Browser Cache and Refresh Application
  • If using WP Caching Plugins, Use them to Purge Cache and then Disable the Plugins temporarily 
WP Super Cache Plugin - goto settings via Settings => WP Super Cache => Contents in your WordPress dashboard and click the Delete Cache button.
  • Find Cache Files on your Server or WP App directories.
  • Backup and delete all files inside the cache directory
public_html/wp-content/cache/
  • Caching Issues while Developing / Coding
If you're modifying theme code or making design changes on a live site whilst
a cache is active, it's different.
You very likely won't be able to see your changes until you clear the cache of your plugin or browser
  • Disabling or Enabling Caching in wp-config.php
Simply add the code : define('WP_CACHE', true);
  • Disabling Plugins when Facing Issues
Use the plugin menu on WP Admin Dashboard if you have access to WP Admin. 
We can deactivate all plugins by renaming your plugins folder (/public_html/wp-content/plugins )
  • Inserting Cache-Control Code to App Script File (PHP or HTML )
HTML File To use cache-control in HTML, you use the meta tag,
<meta http-equiv="Cache-control" content="public"> . Read More

PHP File
To use cache-control in PHP, you have to Set the PHP Headers
<?php
//set headers to NOT cache a page
header("Cache-Control: no-cache, must-revalidate"); //HTTP 1.1
header("Pragma: no-cache"); //HTTP 1.0
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
//or, if you DO want a file to cache, use:
header("Cache-Control: max-age=2592000"); //30days (60sec * 60min * 24hours * 30days)
?>
  • Editing the .htaccess file with Cache-Control Code (Final Solution)
However, beware of the time you leave the contents in the cache.
Where: 604800 = 7 days. (60s * 60 * 24 * 7 = 604800)

Add this to your root .htaccess file and save the file in the specific web application root folder (Note: This can be used to reset any header).

<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>

This goes in your root .htaccess file but if you have access to httpd.conf that is better.
This code uses the FilesMatch directive and the Header directive to add Cache-Control Headers to certain files.

Related Resources

- I have made some changes on my WordPress site but they are not showing
when I try to access it.
- This issue is most often caused by the cache functionality of WordPress.
- To see your changes, you should clear your WordPress cache.
- The cache is located in a folder called /wp-content/cache/.
- You should delete the content of the cache/ folder either by FTP or via File Manager in cPanel, clear the cache of your web browser and reload your website.

Potential Related Research Questions

  • Online way to check if a website has a cache problem?
  • php file cache-control


0 comments :

Post a Comment