5. Cache Management
First explain, the reason why Cache Management is listed,
Is to explain the importance of data cache! In many cases, this is more than writing Data
Access logic is more expensive and more difficult to grasp.
The author's Cache Management implemented Data Cache
Several questions must be considered, although it is not perfect, but it can also be used in actual combat!
Here, it is a structure diagram:
From the figure, it can be obvious, this Cache Management program
Mainly consisting of 3 parts: Manager Class, Delegate Declaration, Parameter
Classes!
Manager is a total console, all calls are completed by it,
The interface also exhibits certain simplicity as much as possible. At the same time, due to Cache
Management is generally implemented throughout Application Level, so there is no
If you have questions, CacheManager automatically became a Singleton!
From the above figure, we are not difficult to find that CacheManager provides true
The positive data access method has only one: getCache (the other is Singleton Access,
Not counting J)!
Ok, let's take a look at this getCache what to do with:
Code 14: Explore the CacheManager GetCache!
Public Delegate ArrayList GetArrayList ();
Public Class CacheManager
{
// Dummy Object for ensuring the Thread-Safe operation in Singleton
Private static Object _currentlocker = new object ();
// STATIC Object for implementing Singleton
Private static cachemanager _current = null;
// Cache Data for storing Windows Application
Private hashtable _htwinappcache = null;
Public ArrayList Getcache (CacheParam Param, GetArrayList Del)
{
IF (param == NULL)
Return del ();
Else
{
IF (ISCACHEEXPIRED (param.name))
Return (ArrayList) Updatecche (param, del ());
Else
Return (ArrayList) RetrieVecache (param.name);
}
}
...
}
Wow, it turned out to be "lie"! This so-called "one method" is actually returned to the Object type, but also "vibrating the word" stands for a mandatory type conversion!
Yes, this DAF Solution is only available for Cache Management for ArrayList, and if you need to extend it to other types, you must provide the corresponding delegate declaration outside of the new GetCache method!
However, please believe that the author is so arranged to be purely for code modification and compile (this article has declared, you can compile the code for .NET Framework 1.2 by Visual Studio .NET 2003), do not "deceive" Ji J ! In the above, when telling the Data Access Logic, Anonymous Delegate has been mentioned, although this new feature is only supported in C # 2.0, but there is a relatively simple working method to ensure your code compiled in C # 1.0 Compiler (please refer to Code 11 later described). However, if the author uses generics in Cachemanager (another feature that only supports only in C # 2.0 only), "only a getcache method" CacheManager, reverse adjustment is very troublesome (let it in Visual Studio .NET) Compiled in 2003, so, in this release, the "rustic" method J is used, which does not affect the practical function of the cache management (interested friends can try to implement CacheManager with generics, but don't Forgot Delegate, you must also declare in generic! In addition, Delegate Parameter List can be passed by declaring "Object []" and combined with Reflection technology!)
Next paragraph: http://www.9cbs.net/develop/read_article.asp? Id = 27560