Image Cache Control

An Overview

The new image caching system has shown to save time during import, and increase the overall server stability, both during import and during display of the imported images on the frontend.

It works by saving remote images locally, and then running checks and operations on local files, so as to avoid re-downloading them. This includes size checks, especially during auto-detection; attaching images to posts and assigning them as the featured image; and generation of thumbnails on the frontend.

There are a few things to keep in mind, however, with this new approach.

The first is that each image is considered valid for a certain amount of time, after which it will be re-downloaded when it is accessed again. While this approach can save a lot of time, in some cases it may be desirable to clear the cache to save space, or perhaps to invalidate all cache so that all images are downloaded again when necessary.

Another important point is being able to control some aspects of the caching. This could be especially useful during testing, or if a problem is encountered.

All Plugins

All these images need to be saved locally in order to make cache effective. But where would they be saved? This depends on the settings of your WordPress environment, as well as the operating system your server is running on. Generally, each image cache file will be located at a path that can be represented like this:

  • [%tmp%] – This is the temporary folder on your system, and is largely determined by the return value of get_temp_dir(). As the WordPress documentation states, the first place this function will consider is the path specified by the WP_TEMP_DIRconstant, which typically lives in your wp-config.php file. If no such constant exist, then in most cases your operating system’s temporary folder is used. On Windows, this can be accessed by typing %tmp% in the Explorer’s address bar, and is explained in more detail here. On Unix systems this can be /var/tmp/ or /tmp/, among many others. For more information, please consult your operating system’s documentation.
  • remote-image-cache – The base folder of the WP RSS Aggregator specific caching system.
  • [domain] – The domain, on which the remote resource is located.
  • [slug] – A part of the original filename, no longer than 25 chars.
  • [complete-url-hash] – A hash of the whole URL of the remote resource, including the protocol, port and any parameters. This allows different versions of the same image to live alongside each other.
  • [extension] – The file extension of the original resource.

In light of the above, given that the server operates under the user “wprssa”, and is running on Windows, the image at this URL could be cached locally at the following path:


Feed to Post

We have decided that it could be helpful to expose control over the image cache TTL (Time To Live) via the WPRSS_FTP_IMAGE_CACHE_TTL constant. Defined in your wp-config.php, this would allow you to control the amount of time, for which the cached images will be considered valid. The default value is 1 week, but it’s possible to change this to any other amount of time, by specifying the amount in seconds. Here’s an example of what this could look like:

define('WPRSS_FTP_IMAGE_CACHE_TTL',60*60*24);// 1 day<br>

Please note that for the cache to be effective, it’s best to set this value to something large, such as a few days. In most cases the default configuration will suffice.

This value can also be overridden programmatically in a plugin or theme via the wprss_f2p_image_cache_ttl filter.

Another interesting constant is WPRSS_FTP_IMAGE_CACHE_DOWNLOAD_REQUEST_TIMEOUT , which is by default set to one minute. If you are having problems getting remote images to import, and you think that the problem may be the remote server’s response time, you could try giving it a larger value in seconds.

To override this value programmatically, please use the wprss_f2p_image_cache_download_request_timeout filter.

Excerpts & Thumbnails

This plugin has a constant for controlling the cache TTL, similarly to Feed to Post, and is named WPRSS_ET_IMAGE_CACHE_TTL. It works in an identical fashion, and it’s default value is also 1 week.

The wprss_et_image_cache_ttl filter provides a way to programmatically change this value via a plugin or theme.

Since the Excerpts & Thumbnails plugin performs less operations on images, we have decided to keep it simple for now; thus, this is the only constant currently available for this plugin that can be used to control the cache.

Still need help? Contact Us Contact Us