ImageResizer.Plugins.DiskCache If the collection contains the specified item, it is returned. Otherwise, null is returned. Returns how many bytes are allocated by buffers in the queue. May be 2x the amount of data. Represents how much ram is being used by the queue, not the amount of encoded bytes that will actually be written. Removes the specified object based on its relativepath and modifieddateutc values. Returns false when (a) the specified AsyncWrite value already exists, (b) the queue is full, or (c) the thread pool queue is full How many bytes of buffered file data to hold in memory before refusing futher queue requests and forcing them to be executed synchronously. Wraps the data in a readonly MemoryStream so it can be accessed on another thread Returns the UTC time this AsyncWrite object was created. Defaults to 10MB limit, and samples usage over the last 10 minutes when deciding what to remove. Stuff not used in the last 10 minutes gets discarded even if the limit hasn't been reached. Implements IHttpHandler, serves content for the NoCache plugin Throws an exception if the class is already modified Loads the settings from 'c', starts the cache, and registers the plugin. Will throw an invalidoperationexception if already started. Returns true if the configured settings are valid and .NET (not NTFS) permissions will work. Returns true if .NET permissions allow writing to the cache directory. Does not check NTFS permissions. 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() Returns true if stopped succesfully. Cannot be restarted 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. Returns the physical path of the cache directory specified in VirtualCacheDir. Returns true if the DiskCache instance is operational. The estimated ram usage for the entire cache. Relies upon the accuracy of the calculator delegate Specifies counter granularity, memory limits, cleanup intervals, and threading optimization level. Whether to optimize for performance or counter accuracy. Defaults to Fast How granular to track the time. For example, with a granularity of 8 (default), and an 8-minute tracking duration, the counter will track the last 7-8 minutes (maximum 0-59.9 second time window variance). Specifies a hard limit on the number of bytes used for tracking purposes. Causes the smallest-valued items to get discarded first. Doesn't count key size unless SetCustomSize is called on the items. Set to 0 to disable (default) Specifies how often to eliminate 0-valued items from the dictionary. Defaults to 20 seconds. Only potentially triggered by .Increment() or PingCleanup() calls. The estimated size (in bytes) of a counter (excluding the key). Based on CounterGranularity Much faster than accurate mode, but at the expense of extremely rare counter inaccuracies. Irrelevant in light of counter granularity, usually. Maintains a dictionary of keys to counters. Counters track how many events have occured during the last X minutes/seconds/ticks for the given item. Can enforce size limits and cleanup empty counters on an inverval. For incrementing and finding counters based on keys Purely for cleanup purposes. Allows fast removal of pairs based on the EventCounter instance. Lock for access to dictionaries Lock on EventCounter.sortValue members. Redundant with cleanupLock implemented. Lock to prevent concurrent cleanups from occuring Lock to prevent duplicate work items from being scheduled. Starts cleanup on a thread pool thread if it hasn't been started within the desired interval. If cleanup starts and other cleanup is running, it cancels. The assumption is that one cleanup of either type is enough within the interval. Performs cleanup on the dictionaries in either MakeRoom or Maintenance mode. Returns true if the goal was achieved, false if the cleanup was canceled because another cleanup was executing conurrently. Increment the counter for the given item. Pings cleanup as well. Sets the custom size offset for the specified key (used for cleanup purposes). If -1, existing value will remain unchanged. Calculate the counter value for the given item The duration for which to track events. For example, 5 minutes will keep a rolling value of how many events have occured in the last 5 minutes The estimated number of bytes used for tracking, plus the sum of the CustomSize values. Key space not included unless the caller always includes key size in CustomSize parameter. Maintains a rotating data structure to track events over a moving time period. Returns the value of the counter Warning! Not synchronized or updated. Use must be externally synchromized and value set externally User-defined size of related item (key and/or a related cache object). Defaults to 0; Uses old.AccessedUtc if it is newer than FileInfo.LastAccessTimeUtc The modified date of the source file that the cached file is based on. The last time the file was accessed. Will not match NTFS date, this value is updated by DiskCache. When first loaded from NTFS, it will be granular to about an hour, due to NTFS delayed write. Also, windows Vista and higher never write accessed dates. We update this value in memory, and flush it to disk lazily. The Created date of the cached file - the last time the cached file was written to Represents a cached view of a folder of cached items Returns null if (a) the file doesn't exist, or (b) the file isn't populated. Calling code should always fall back to filesystem calls on a null result. Sets the CachedFileInfo object for the specified path, creating any needed folders along the way. If 'null', the item will be removed, and no missing folder will be created. Tries to set the AccessedUtc of the specified file to the current date (just in memory, not on the filesystem). Gets a CachedFileInfo object for the file even if it isn't in the cache (falls back to the filesystem) Verifies the file exists before returning the cached data. Discrepancies in file existence result in OnFileDisappeard being fired. Returns the value of IsValid on the specified folder if present, or 'false' if not present. Not thread safe. returns a list returns a dictionary of files. returns a dictionary of files. Refreshes file and folder listing for this folder (non-recursive). Sets IsValid=true afterwards. Updates the 'folders' dictionary to match the folders that exist on disk. ONLY UPDATES THE LOCAL FOLDER Updates the 'files' dictionary to match the files that exist on disk. Uses the accessedUtc values from the previous dictionary if they are newer. Returns true if both dates are equal to the nearest 200th of a second. Defaults to false. Set to true immediately after being refreshed from the filesystem. Set to false if a file disappears from the filesystem cache without the cache index being notified first. Used by the cleanup system - not of importance to the cache write system. Fired when a file disappears from the cache folder without the cache index knowing about it. Provides thread-safe access to the index of the disk cache Failed to acquire a lock on the cached item within the timeout period The item wasn't cached, but was successfully added to the cache (or queued, in which case you should read .Data instead of .PhysicalPath) The item was already in the cache. The physical path to the cached item. Verify .Data is null before trying to read from this file. Provides a read-only stream to the data. Usually a MemoryStream instance, but you should dispose it once you are done. If this value is not null, it indicates that the file has not yet been written to disk, and you should read it from this stream instead. The path relative to the cache The result of the cache check Notifies the CleanupManager that a request is in process. Helps CleanupManager optimize background work so it doesn't interfere with request processing. Notifies the CleanupManager that a file was added under the specified relative path. Allows CleanupManager to detect when a folder needs cleanup work. When true, indicates that another process is managing cleanup operations - this thread is idle, waiting for the other process to end before it can pick up work. Queues the item if no other identical items exist in the queue. Returns true if the item was added. Inserts the specified list of items and the end of the queue. They will be next items popped. They will pop off the list in the same order they exist in 'items' (i.e, they are inserted in reverse order). Performs an atomic clear and enqueue of the specified item Creates and starts a thread that consumes the queue, pausing until notified when 'queue' empties. Tells the worker to check the queue for more work. The last time a cache folder exceeded both the optimum and maximum limits for file count. If recent, indicates a misconfiguration; the subfolders="" count needs to be increased. The last time a cache query came through Tells the worker to avoid work for a little bit. The last time we did work (or attempted to do work, failing if the queue was empty) When true, indicates that another process is managing cleanup operations - this thread is idle, waiting for the other process to end before it can pick up work. Thread runs this method. Processes work items from the queue, using at most 50% Processes items from the queue for roughly the specified amount of time. Returns false if the queue was empty. When true, indicates that another process is managing cleanup operations - this thread is idle, waiting for the other process to end before it can pick up work. An item in the work queue Should be a delegate a CleanupWorkItem instance (which doesn't have LazyProvider value, but has RelativePath and PhyscialPath values). May return null Cache-relative path Physcial path If the .IsValid is false, populates the folder, enqueing more PopulateFolderRecursive items for all subfolders discovered. Sets IsValid to true Requires a valid folder. Cleans the folder, enqueing RemoveFile tasks for everything that needs to be removed. Populates (non-recursive) the files and folders inside the specified directory. Removes a single file, with the file and dir being determined at executing time via the LazyProvider delegate. Calls File.SetLastAccessedTimeUtc() using the in-memory value, if present. Handles access to a disk-based file cache. Handles locking and versioning. Supports subfolders for scalability. If the cached data exists and is up-to-date, returns the path to it. Otherwise, this function tries to cache the data and return the path. The basis for the key. Should not include the modified date, that is handled inside the function. The extension to use for the cached file. A method that accepts a Stream argument and writes the data to it. The modified date of the source file. Should be DateTime.MinValue if not available May return either a physical file name or a MemoryStream with the data. Faster than GetCachedFile, as writes are (usually) asynchronous. If the write queue is full, the write is forced to be synchronous again. Identical to GetCachedFile() when asynchronous=false Returns true if either (a) the file was written, or (b) the file already existed with a matching modified date. Returns false if the in-process lock failed. Throws an exception if any kind of file or processing exception occurs. Fired immediately before GetCachedFile return the result value. Provides string-based locking for file write access. Provides string-based locking for image resizing (not writing, just processing). Prevents duplication of efforts in asynchronous mode, where 'Locks' is not being used. Contains all the queued and in-progress writes to the cache. Provides an in-memory index of the cache. Indicates a problem with disk caching. Causes include a missing (or too small) ImageDiskCacheDir setting, and severe I/O locking preventing the cache dir from being cleaned at all. Provides methods for creating, maintaining, and securing the disk cache. Throws an exception if the class is already modified Creates a disk cache in the /imagecache folder Creates a DiskCache instance at the specified location. Must be installed as a plugin to be operational. Uses the defaults from the resizing.diskcache section in the specified configuration. Throws an invalid operation exception if the DiskCache is already started. Loads the settings from 'c', starts the cache, and registers the plugin. Will throw an invalidoperationexception if already started. Returns true if the configured settings are valid and .NET (not NTFS) permissions will work. Returns true if .NET permissions allow writing to the cache directory. Does not check NTFS permissions. 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() Returns true if stopped succesfully. Cannot be restarted Controls how many subfolders to use for disk caching. Rounded to the next power of to. (1->2, 3->4, 5->8, 9->16, 17->32, 33->64, 65->128,129->256,etc.) NTFS does not handle more than 8,000 files per folder well. Larger folders also make cleanup more resource-intensive. Defaults to 32, which combined with the default setting of 400 images per folder, allows for scalability to 12,800 actively used image versions. For example, given a desired cache size of 100,000 items, this should be set to 256. Allows disk caching to be disabled for debuginng purposes. Defaults to true. If true, items from the cache folder will be automatically 'garbage collected' if the cache size limits are exceeded. Defaults to false. Only relevant when AutoClean=true. Settings about how background cache cleanup are performed. It is best not to modify these settings. There are very complicated and non-obvious factors involved in their choice. How many milliseconds to wait for a cached item to be available. Values below 0 are set to 0. Defaults to 15 seconds. Actual time spent waiting may be 2 or 3x this value, if multiple layers of synchronization require a wait. If true, when a source file is changed, a new file will be created instead of overwriting the old cached file. This helps prevent file lock contention on high-traffic servers. Defaults to true. Do NOT set this to false in a Web Garden or if you have overlapped recycle enabled, as you may risk having occasional failed requests due to write contention by separate proccesses. Changes the hash function, so you should delete the cache folder whenever this setting is modified. If true, writes to the disk cache will be performed outside the request thread, allowing responses to return to the client quicker. If more than this amount of memory (in bytes) is currently allocated by queued writes, the request will be processed synchronously instead of asynchronously. 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. Returns the physical path of the cache directory specified in VirtualCacheDir. Returns true if the DiskCache instance is operational. Loads settings from the specified node. Attribute names and property names must match. Saves the current settings to the dictionary of default settings. Restores the default property valies How long to wait before beginning the initial cache indexing and cleanup. The minimum amount of time to wait after the most recent BeLazy to begin working again. The maximum amount of time to wait between work segements The optimal length for a work segment. Not always achieved. The ideal number of cached files per folder. (defaults to 400) Only reached if it can be achieved without volating the AvoidRemoval... limits The maximum number of cached files per folder. (defaults to 1000) Only reached if it can be achieved without violating the ProhibitRemoval... limits Please note "LastUsed" values are (initially) only accurate to about a hour, due to delayed write. If a file has been used after the app started running, the the last used date is accurate. Please note "LastUsed" values are (initially) only accurate to about a hour, due to delayed write. If a file has been used after the app started running, the the last used date is accurate. Provides locking based on a string key. Locks are local to the LockProvider instance. The class handles disposing of unused locks. Generally used for coordinating writes to files (of which there can be millions). Only keeps key/lock pairs in memory which are in use. Thread-safe. The only objects in this collection should be for open files. Synchronization object for modifications to the 'locks' dictionary Returns true if the given key *might* be locked. Attempts to execute the 'success' callback inside a lock based on 'key'. If successful, returns true. If the lock cannot be acquired within 'timoutMs', returns false In a worst-case scenario, it could take up to twice as long as 'timeoutMs' to return false. Defaults to 10MB limit, and samples usage over the last 10 minutes when deciding what to remove. Stuff not used in the last 10 minutes gets discarded even if the limit hasn't been reached. Builds a key for the cached version, using the hashcode of the normalized URL. if subfolders > 1, dirSeparator will be used to separate the subfolder and the key. No extension is appended. I.e, a13514\124211ab132592 or 12412ababc12141 Returns a string for the subfolder name. The bits used are from the end of the hash - this should make the hashes in each directory more unique, and speed up performance (8.3 filename calculations are slow when lots of files share the same first 6 chars. Returns null if not configured. Rounds subfolders up to the nearest power of two. Handles writing a Web.Config to disk that uses Url Authorization to prevent visitors from accessing the files directly. Alternative Web.config content can be specified, this is a general-purpose implementation. Uses UTF-8 encoding. Also provides methods for efficient verification that the file still exists. Thread-safe. This string contains the contents of a web.conig file that sets URL authorization to "deny all" inside the current directory. Verifies a Web.config file is present in the directory every 5 minutes that the function is called, including the first time. If CheckWebConfig has never executed, it is executed immediately, but only once. Verifies a Web.config file is present in the directory, and creates it if needed. Verifies a Web.config file is present in the directory, and creates it if needed. Should only be called inside a lock. Creates the cache dir and the web.config file if they are missing. Updates _lastCheckedWebConfig and _checkedWebConfigOnce