ImageResizer  3.4.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events
Public Member Functions | Public Attributes | List of all members
ImageResizer.Plugins.TinyCache.CacheEntry Class Reference

Public Member Functions

float GetPreservationPriority ()
 Returns a number between 0 and 1, where 1 is the highest preservation reccomendation More...
 

Public Attributes

int cost_ms = -1
 Time it took to generate the content More...
 
int recreated_count = 0
 How many times the data has been recreated (not accurate, but very useful for cache sorting) More...
 
int read_count = 0
 How many times the data has been read More...
 
Queue< DateTime > recent_reads = new Queue<DateTime>(8)
 (utc) last 8 accesses More...
 
DateTime written
 (utc) When the entry was first added to the cache, ever More...
 
DateTime loaded
 (utc) when the cache was last loaded from disk More...
 
int sizeInBytes
 Size of 'data' in bytes, even when null More...
 
byte[] data
 

Detailed Description

Definition at line 9 of file CacheEntry.cs.

Member Function Documentation

float ImageResizer.Plugins.TinyCache.CacheEntry.GetPreservationPriority ( )
inline

Returns a number between 0 and 1, where 1 is the highest preservation reccomendation

Returns

Definition at line 59 of file CacheEntry.cs.

59  {
60 
61  //100kb -> 0.39 8kb -> 0.88 2mb -> 0.03
62  float size = 1 / (1 + ((float)sizeInBytes / (64.0f * 1024.0f)));
63 
64  float size_weight = 1;
65 
66  //Get cost between 0 and 1, where 100ms equates to 0.02 and 800ms equates to 0.16
67  float cost = Math.Max(0.00001f,(float)Math.Min(cost_ms, 5000) / 5000.0f);
68 
69  float cost_weight = 2;
70 
71  var now = DateTime.UtcNow;
72  //Average reads/minute over lifetime (maxed at 1, min at 0)
73  float overall_usage = (float)Math.Max(1.0, (double)read_count / Math.Max(0.1, now.Subtract(written).TotalMinutes));
74 
75  //We don't weight it unless it's been written for a while.
76  float overall_usage_weight = 1 - (float)(Math.Max(30,now.Subtract(written).TotalMinutes) /30);
77 
78  //How long has it been since the average of the last 8 reads?
79  //Divide by last 30 minutes
80  float recent_usage = (float)Math.Min(0, 1 - Math.Max(30, recent_reads.Average(d => now.Subtract(d).TotalMinutes)) / 30.0);
81 
82  float recent_usage_weight = 1 - (float)(Math.Max(30, now.Subtract(loaded).TotalMinutes) / 30);
83 
84  //If the entry has been cleared and recreated
85  float recreated = Math.Max(10, Math.Min(0,recreated_count)) / 10.0f;
86 
87  float recreated_weight = 4;
88 
89  float result= size * size_weight + cost * cost_weight + overall_usage * overall_usage_weight + recent_usage * recent_usage_weight + recreated * recreated_weight;
90 
91  return result / (size_weight + cost_weight + overall_usage_weight + recent_usage_weight + recreated_weight);
92  }
int cost_ms
Time it took to generate the content
Definition: CacheEntry.cs:15
int sizeInBytes
Size of &#39;data&#39; in bytes, even when null
Definition: CacheEntry.cs:48
Queue< DateTime > recent_reads
(utc) last 8 accesses
Definition: CacheEntry.cs:31
int recreated_count
How many times the data has been recreated (not accurate, but very useful for cache sorting) ...
Definition: CacheEntry.cs:20
DateTime loaded
(utc) when the cache was last loaded from disk
Definition: CacheEntry.cs:43
int read_count
How many times the data has been read
Definition: CacheEntry.cs:26
DateTime written
(utc) When the entry was first added to the cache, ever
Definition: CacheEntry.cs:37

Member Data Documentation

int ImageResizer.Plugins.TinyCache.CacheEntry.cost_ms = -1

Time it took to generate the content

Definition at line 15 of file CacheEntry.cs.

DateTime ImageResizer.Plugins.TinyCache.CacheEntry.loaded

(utc) when the cache was last loaded from disk

Definition at line 43 of file CacheEntry.cs.

int ImageResizer.Plugins.TinyCache.CacheEntry.read_count = 0

How many times the data has been read

Definition at line 26 of file CacheEntry.cs.

Queue<DateTime> ImageResizer.Plugins.TinyCache.CacheEntry.recent_reads = new Queue<DateTime>(8)

(utc) last 8 accesses

Definition at line 31 of file CacheEntry.cs.

int ImageResizer.Plugins.TinyCache.CacheEntry.recreated_count = 0

How many times the data has been recreated (not accurate, but very useful for cache sorting)

Definition at line 20 of file CacheEntry.cs.

int ImageResizer.Plugins.TinyCache.CacheEntry.sizeInBytes

Size of 'data' in bytes, even when null

Definition at line 48 of file CacheEntry.cs.

DateTime ImageResizer.Plugins.TinyCache.CacheEntry.written

(utc) When the entry was first added to the cache, ever

Definition at line 37 of file CacheEntry.cs.


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