XF 1.5 Changing Image Cache Lifetime

0ptima

Well-known member
I currently have my image cache lifetime set to 0 to retain images indefinitely and have been caching images for close to two years. If I set the retention period to 365 days, will all images older than 365 days be deleted at once? Will this strain the server?
 
I currently have my image cache lifetime set to 0 to retain images indefinitely and have been caching images for close to two years. If I set the retention period to 365 days, will all images older than 365 days be deleted at once? Will this strain the server?

Yes. Maybe.

You should manually run this cron after the change to make sure it completes:

Admin CP -> Tools -> Cron Entries -> Hourly Clean Up

If it doesn't complete then it might be due to the image proxy pruning, and you might consider temporarily setting a batch limit in the code (arbitrarily set to 5000 in this example):

library/XenForo/Model/ImageProxy.php

Rich (BB code):
	/**
	 * Prunes images from the file system cache that have expired
	 *
	 * @param integer|null $pruneDate
	 */
	public function pruneImageCache($pruneDate = null)
	{
		$db = $this->_getDb();

		if ($pruneDate === null)
		{
			if (!XenForo_Application::getOptions()->imageCacheTTL)
			{
				return;
			}

			$pruneDate = XenForo_Application::$time - (86400 * XenForo_Application::getOptions()->imageCacheTTL);
		}

		$images = $this->fetchAllKeyed('
			SELECT *
			FROM xf_image_proxy
			WHERE fetch_date < ?
				AND pruned = 0
			LIMIT 0, 5000
		', 'image_id', $pruneDate);

		if ($images)
		{
			foreach ($images AS $imageId => $image)
			{
				$this->_deleteFile($image);
			}

			$db->update('xf_image_proxy', array(
				'pruned' => 1
			), 'image_id IN (' . $db->quote(array_keys($images)) . ')');
		}
	}

The idea here is that it will process 5000 records each time the hourly cleanup is run.
 
Top Bottom