ImageResizer  3.4.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | Properties | List of all members
ImageResizer.Plugins.SourceDiskCache.SourceDiskCachePlugin Class Reference
Inheritance diagram for ImageResizer.Plugins.SourceDiskCache.SourceDiskCachePlugin:
Inheritance graph
[legend]
Collaboration diagram for ImageResizer.Plugins.SourceDiskCache.SourceDiskCachePlugin:
Collaboration graph
[legend]

Classes

class  SourceVirtualFile
 

Public Member Functions

IVirtualFile GetFileIfCached (string virtualPath, System.Collections.Specialized.NameValueCollection queryString, IVirtualFile original)
 
IPlugin Install (Config c)
 Loads the settings from 'c', starts the cache, and registers the plugin. Will throw an invalidoperationexception if already started. More...
 
bool Uninstall (Config c)
 Uninstalls the plugin. Should reverse all changes made during Install More...
 
bool IsConfigurationValid ()
 Returns true if the configured settings are valid and .NET (not NTFS) permissions will work. More...
 
bool Start ()
 Attempts to start the DiskCache using the current settings. Returns true if succesful or if already started. Returns false on a configuration error. Called by Install() More...
 
bool Stop ()
 Returns true if stopped succesfully. Cannot be restarted More...
 
- Public Member Functions inherited from ImageResizer.Plugins.IVirtualFileCache
IVirtualFile GetFileIfCached (string virtualPath, NameValueCollection queryString, IVirtualFile original)
 Returns a cached copy of virtual file if it is cached, and if caching is desired. More...
 

Protected Member Functions

void BeforeSettingChanged ()
 Throws an exception if the class is already modified More...
 
bool HasFileIOPermission ()
 Returns true if .NET permissions allow writing to the cache directory. Does not check NTFS permissions. More...
 

Protected Attributes

string virtualDir = HostingEnvironment.ApplicationVirtualPath.TrimEnd('/') + "/cache/sourceimages"
 
CustomDiskCache cache = null
 
CleanupManager cleaner = null
 
WebConfigWriter writer = null
 
readonly object _startSync = new object()
 
volatile bool _started = false
 
ILogger log = null
 

Properties

string VirtualCacheDir [get, set]
 Sets the location of the cache directory. Can be a virtual path (like /App/imagecache) or an application-relative path (like ~/imagecache, the default). Relative paths are assummed to be relative to the application root. All values are converted to virtual path format upon assignment (/App/imagecache) Will throw an InvalidOperationException if changed after the plugin is installed. More...
 
string PhysicalCacheDir [get]
 Returns the physical path of the cache directory specified in VirtualCacheDir. More...
 
bool Started [get]
 Returns true if the DiskCache instance is operational. More...
 
ILogger Logger [get]
 
- Properties inherited from ImageResizer.Configuration.Logging.ILoggerProvider
ILogger Logger [get]
 

Detailed Description

Definition at line 17 of file SourceDiskCache.cs.

Member Function Documentation

void ImageResizer.Plugins.SourceDiskCache.SourceDiskCachePlugin.BeforeSettingChanged ( )
inlineprotected

Throws an exception if the class is already modified

Definition at line 57 of file SourceDiskCache.cs.

58  {
59  if (_started) throw new InvalidOperationException("SourceDiskCache settings may not be adjusted after it is started.");
60  }
bool ImageResizer.Plugins.SourceDiskCache.SourceDiskCachePlugin.HasFileIOPermission ( )
inlineprotected

Returns true if .NET permissions allow writing to the cache directory. Does not check NTFS permissions.

Returns

Definition at line 176 of file SourceDiskCache.cs.

176  {
177  FileIOPermission writePermission = new FileIOPermission(FileIOPermissionAccess.AllAccess,new string[]{PhysicalCacheDir, Path.Combine(PhysicalCacheDir,"web.config")});
178  return SecurityManager.IsGranted(writePermission);
179  }
string PhysicalCacheDir
Returns the physical path of the cache directory specified in VirtualCacheDir.
IPlugin ImageResizer.Plugins.SourceDiskCache.SourceDiskCachePlugin.Install ( Config  c)
inline

Loads the settings from 'c', starts the cache, and registers the plugin. Will throw an invalidoperationexception if already started.

Parameters
c
Returns

Implements ImageResizer.Plugins.IPlugin.

Definition at line 134 of file SourceDiskCache.cs.

134  {
135  if (c.get("diskcache.logging", false)) {
136  if (c.Plugins.LogManager != null)
137  log = c.Plugins.LogManager.GetLogger("ImageResizer.Plugins.DiskCache");
138  else
139  c.Plugins.LoggingAvailable += delegate(ILogManager mgr) {
140  if (log != null) log = c.Plugins.LogManager.GetLogger("ImageResizer.Plugins.DiskCache");
141  };
142  }
143 
144  Start();
145  c.Pipeline.AuthorizeImage += Pipeline_AuthorizeImage;
146  c.Plugins.add_plugin(this);
147  return this;
148  }
ILogManager LogManager
Returns the most recently registered Logging plugin, or null.
PluginConfig Plugins
Access and modify plugins
Definition: Config.cs:85
bool Start()
Attempts to start the DiskCache using the current settings. Returns true if succesful or if already s...
bool ImageResizer.Plugins.SourceDiskCache.SourceDiskCachePlugin.IsConfigurationValid ( )
inline

Returns true if the configured settings are valid and .NET (not NTFS) permissions will work.

Returns

Definition at line 167 of file SourceDiskCache.cs.

168  {
169  return !string.IsNullOrEmpty(VirtualCacheDir) && HasFileIOPermission();
170  }
string VirtualCacheDir
Sets the location of the cache directory. Can be a virtual path (like /App/imagecache) or an applicat...
bool HasFileIOPermission()
Returns true if .NET permissions allow writing to the cache directory. Does not check NTFS permission...
bool ImageResizer.Plugins.SourceDiskCache.SourceDiskCachePlugin.Start ( )
inline

Attempts to start the DiskCache using the current settings. Returns true if succesful or if already started. Returns false on a configuration error. Called by Install()

Definition at line 186 of file SourceDiskCache.cs.

187  {
188  if (!IsConfigurationValid()) return false;
189  lock (_startSync)
190  {
191  if (_started) return true;
192  if (!IsConfigurationValid()) return false;
193 
194  //Init the writer.
195  writer = new WebConfigWriter(this, PhysicalCacheDir);
196  //Init the inner cache
197  cache = new CustomDiskCache(this, PhysicalCacheDir, 512, true, 1024 * 1024 * 30); //30MB
198  //Init the cleanup strategy
199  var cleanupStrategy = new CleanupStrategy(); //Default settings if null
200  cleanupStrategy.TargetItemsPerFolder = 50;
201  //Init the cleanup worker
202  cleaner = new CleanupManager(this, cache, cleanupStrategy);
203  //If we're running with subfolders, enqueue the cache root for cleanup (after the 5 minute delay)
204  //so we don't eternally 'skip' files in the root or in other unused subfolders (since only 'accessed' subfolders are ever cleaned ).
205  if (cleaner != null) cleaner.CleanAll();
206 
207  //Started successfully
208  _started = true;
209  return true;
210  }
211  }
string PhysicalCacheDir
Returns the physical path of the cache directory specified in VirtualCacheDir.
Handles writing a Web.Config to disk that uses Url Authorization to prevent visitors from accessing t...
bool IsConfigurationValid()
Returns true if the configured settings are valid and .NET (not NTFS) permissions will work...
Handles access to a disk-based file cache. Handles locking and versioning. Supports subfolders for sc...
bool ImageResizer.Plugins.SourceDiskCache.SourceDiskCachePlugin.Stop ( )
inline

Returns true if stopped succesfully. Cannot be restarted

Returns

Definition at line 216 of file SourceDiskCache.cs.

217  {
218  if (cleaner != null) cleaner.Dispose();
219  cleaner = null;
220  return true;
221  }
bool ImageResizer.Plugins.SourceDiskCache.SourceDiskCachePlugin.Uninstall ( Config  c)
inline

Uninstalls the plugin. Should reverse all changes made during Install

Parameters
c
Returns

Implements ImageResizer.Plugins.IPlugin.

Definition at line 156 of file SourceDiskCache.cs.

157  {
158  c.Plugins.remove_plugin(this);
159  c.Pipeline.AuthorizeImage -= Pipeline_AuthorizeImage;
160  return this.Stop();
161  }

Property Documentation

string ImageResizer.Plugins.SourceDiskCache.SourceDiskCachePlugin.PhysicalCacheDir
get

Returns the physical path of the cache directory specified in VirtualCacheDir.

Definition at line 47 of file SourceDiskCache.cs.

bool ImageResizer.Plugins.SourceDiskCache.SourceDiskCachePlugin.Started
get

Returns true if the DiskCache instance is operational.

Definition at line 72 of file SourceDiskCache.cs.

string ImageResizer.Plugins.SourceDiskCache.SourceDiskCachePlugin.VirtualCacheDir
getset

Sets the location of the cache directory. Can be a virtual path (like /App/imagecache) or an application-relative path (like ~/imagecache, the default). Relative paths are assummed to be relative to the application root. All values are converted to virtual path format upon assignment (/App/imagecache) Will throw an InvalidOperationException if changed after the plugin is installed.

Definition at line 30 of file SourceDiskCache.cs.


The documentation for this class was generated from the following file: