Cache Class |
Namespace: ASCOM.Utilities
The Cache type exposes the following members.
| Name | Description | |
|---|---|---|
| Cache |
Default initialiser that does not assign a TraceLogger unless the cache tracing flag is set.
| |
| Cache(TraceLogger) |
Inititialiser that takes a reference to the calling application's trace logger. This ensures that trace output will
appear in context with the applications's own log messages, making it easier to debug the application.
|
| Name | Description | |
|---|---|---|
| PumpMessagesInterval |
Get or set the interval, in milliseconds, between calls to Application.DoEvents to pump Windows messages when throttling the cache read rate.
|
| Name | Description | |
|---|---|---|
| ClearCache |
Remove all items from the cache.
| |
| Dispose |
Reset the PC's timing resolution, if changed, and cleanly dispose of the cache's working memory.
| |
| Get(String) |
Immediatley retrieve an object from the cache with the given name with no throttling.
| |
| Get(String, Double) |
Retrieve an object from the cache with the given name, restricting maximum call frequency to the range 2 to 1000 calls per second if required.
| |
| GetBool(String) |
Immediatley retrieve a boolean value from the cache with the given name with no throttling.
| |
| GetBool(String, Double) |
Retrieve a boolean value from the cache with the given name, restricting maximum call frequency to the range 2 to 1000 calls per second if required.
| |
| GetDouble(String) |
Immediatley retrieve a double value from the cache with the given name with no throttling.
| |
| GetDouble(String, Double) |
Retrieve a double value from the cache with the given name, restricting maximum call frequency to the range 2 to 1000 calls per second if required.
| |
| GetInt(String) |
Immediatley retrieve an integer value from the cache with the given name with no throttling.
| |
| GetInt(String, Double) |
Retrieve an integer value from the cache with the given name, restricting maximum call frequency to the range 2 to 1000 calls per second if required.
| |
| GetString(String) |
Immediatley retrieve a string value from the cache with the given name with no throttling.
| |
| GetString(String, Double) |
Retrieve a string value from the cache with the given name, restricting maximum call frequency to the range 2 to 1000 calls per second if required.
| |
| Remove |
Remove a an item with a specific name from the cache
| |
| Set(String, Object, Double) |
Save an object in the cache with the given name and time to live.
| |
| Set(String, Object, Double, Double) |
Save an object in the cache with the given name and time to live, restricting maximum call frequency to the range 2 to 1000 calls per second if required.
| |
| SetBool(String, Boolean, Double) |
Save a boolean value in the cache with the given name and time to live.
| |
| SetBool(String, Boolean, Double, Double) |
Save a boolean value in the cache with the given name and time to live, restricting maximum call frequency to the range 2 to 1000 calls per second if required.
| |
| SetDouble(String, Double, Double) |
Save a double value in the cache with the given name and time to live.
| |
| SetDouble(String, Double, Double, Double) |
Save a double value in the cache with the given name and time to live, restricting maximum call frequency to the range 2 to 1000 calls per second if required.
| |
| SetInt(String, Int32, Double) |
Save an integer value in the cache with the given name and time to live.
| |
| SetInt(String, Int32, Double, Double) |
Save an integer value in the cache with the given name and time to live, restricting maximum call frequency to the range 2 to 1000 calls per second if required.
| |
| SetString(String, String, Double) |
Save a string value in the cache with the given name and time to live.
| |
| SetString(String, String, Double, Double) |
Save a string value in the cache with the given name and time to live, restricting maximum call frequency to the range 2 to 1000 calls per second if required.
|
Astronomy applications are becoming increasingly sophisticated and frequently employ multi-threading techniques that place increasingly high call rate burdens on drivers. Much hardware remains of modest processing capacity and performance can suffer if hardware controllers have to process an excessive number of requests for information and one of the jobs of the driver is to protect the hardware from this kind of situation. Caching is a helpful technique to combat excessive polling of values that don't change frequently and this component provides a conveniently packaged capability to ease driver development.
This cache will store items against specified keys for configurable periods of time and, when an item exceeds its specified retention time, it will automatically be removed by the cache.
Some applications poll at very high rates, so the cache provides an optional rate limiting capability that can delay execution of "set" and "get" methods to enforce a maximum number of actions per second.
The cache "get" methods will either return the requested item, if present, or will throw a NotInCacheException exception, indicating that the driver should poll the hardware and store the value in the cache before returning it to the caller.
Clients using the cache through COM e.g. from scripting languages , Delphi etc. will find that for each group of overloaded methods e.g. GetDouble, only the method with the largest number of parameters is available. This is due to a COM limitation that doesn't allow access to method overloads. .NET clients have access to all overloads.
Code example
using ASCOM.Utilities; using ASCOM.Utilities.Exceptions; Class Driver const string RIGHT_ASCENSION = "Right Ascension"; Cache myCache = new Cache(); ... double RightAscension { get { try { return cache.GetDouble(RIGHT_ASCENSION); // Get the RA value from the cache, if present, without limiting the number of reads per second // or return cache.GetDouble(RIGHT_ASCENSION, 5.0); // Get the RA value from the cache, if present, limiting the number of reads of this value to 5 per second } catch (NotInCacheException) // Exception thrown because requested value is not in the cache - so get it from hardware, save to the cache and return the value { double newRA = ... // Get value from hardware cache.SetDouble(RIGHT_ASCENSION, newRA, 1.0); // Save the new value to the cache with a timeout of 1 second return newRA; } } }