OFrame Cache Library - The easy & lightweight caching helper for ASP.Net

The OFrame Cache Library is a lightweight library or DLL coded in C# aiming to solve your caching coding problems. Built for performance, the library itself is very small and efficient giving you the required edge to your ASP.Net application. It supports various caching mechanisms yet very straightforward and easy to use with minimal lines of code.

Settings File


Page Cache Code

This code sets the page cache equivalent to the OutputCache tag in ASP.Net. The benefits here is that it can easily be done using this code from codebehind enabling dynamic caching mechanism from inside the website administration panel.

        protected void Page_Load(object sender, EventArgs e)
            //set the pageID, duration in minutes and cache location in the 
            //PageCache.xml file, and then use the below line of code in any page you
            //like and assign the PAGE_ID. This will set the page cache for this page
            //and cache the page for specified duration on specified location


Object Cache Code

The below source code is used to cache any object, in either the SessionState, ApplicationState, MemoryCache, or StaticCache, enabling you to gain performance on your frequent readonly operations from disk, database or a file.

The tedious and complex code is now simplified for your easy cahing requirement and written in such way that it wont require any further modifications to your existing codes.

        //Your current method
        public static MyClass GetData(int id)
            //replace the existing source code with the below line
            return GetData(id, AppConfig.PerformanceMode);
//Method to read the data from Disk or DB or File //Change your current method name to this name or something else public static MyClass GetDataFromFileMethod(int id) { //Put your method source code from the original method over here MyClass entity = new MyClass(); //YOU CODE HERE DISK/FILE/DB OPERATIONS return entity; }
//Add this another method for your caching to take place //The unique key assigned should be unique among the classes used for caching //For MyClass one unique key will be used, and for MyClass2 another unique //key will be used. const string uniqueKey = "__UNIQUE_KEY_TO_IDENTIFY_THIS_OBJECT__"; public static MyClass GetData(id id, PerformanceMode performanceMode) { MyClass keyValue = new MyClass(); //The performance key will separate each object based upon the //Unique key and object ID string performanceKey = uniqueKey + id; Func<int, MyClass> fnc = new Func<int, MyClass>(GetDataFromFileMethod); object[] args = { id }; Utilities.GetPerformance<MyClass>(performanceMode, performanceKey, out keyValue, fnc, args); return keyValue; }