Version 3 end of life
This version of Silverstripe CMS will not recieve any additional bug fixes or documentation updates. Go to documentation for the most recent stable version.

Flushable

Introduction

Allows a class to define it's own flush functionality, which is triggered when flush=1 is requested in the URL. FlushRequestFilter is run before a request is made, calling flush() statically on all implementors of Flushable.

Usage

To use this API, you need to make your class implement Flushable, and define a flush() static function, this defines the actions that need to be executed on a flush request.

Using with SS_Cache

This example uses SS_Cache in some custom code, and the same cache is cleaned on flush:

	<?php
	class MyClass extends DataObject implements Flushable {
	
		public static function flush() {
			SS_Cache::factory('mycache')->clean(Zend_Cache::CLEANING_MODE_ALL);
		}
	
		public function MyCachedContent() {
			$cache = SS_Cache::factory('mycache')
			$something = $cache->load('mykey');
			if(!$something) {
				$something = 'value to be cached';
				$cache->save($something, 'mykey');
			}
			return $something;
		}
	
	}

Another example, some temporary files are created in a directory in assets, and are deleted on flush. This would be useful in an example like GD or Imagick generating resampled images, but we want to delete any cached images on flush so they are re-created on demand.

	<?php
	class MyClass extends DataObject implements Flushable {
	
		public static function flush() {
			foreach(glob(ASSETS_PATH . '/_tempfiles/*.jpg') as $file) {
				unlink($file);
			}
		}
	
	}