Click here to Skip to main content
15,878,030 members
Home / Discussions / Design and Architecture
   

Design and Architecture

 
GeneralA re-introduction to TDD Pin
Brady Kelly9-Mar-09 2:09
Brady Kelly9-Mar-09 2:09 
GeneralHigh Level Design for Installation and Upgrade Application Pin
Brady Kelly6-Mar-09 8:49
Brady Kelly6-Mar-09 8:49 
GeneralRe: High Level Design for Installation and Upgrade Application Pin
Jonathan Davies8-Mar-09 4:11
Jonathan Davies8-Mar-09 4:11 
GeneralRe: High Level Design for Installation and Upgrade Application Pin
Brady Kelly8-Mar-09 4:25
Brady Kelly8-Mar-09 4:25 
GeneralRe: High Level Design for Installation and Upgrade Application Pin
Jonathan Davies8-Mar-09 5:25
Jonathan Davies8-Mar-09 5:25 
GeneralRe: High Level Design for Installation and Upgrade Application Pin
Brady Kelly8-Mar-09 5:47
Brady Kelly8-Mar-09 5:47 
QuestionCache Manager design problem Pin
Steve Holdorf28-Feb-09 9:07
Steve Holdorf28-Feb-09 9:07 
QuestionRe: Cache Manager design problem [modified] Pin
Steve Holdorf28-Feb-09 14:34
Steve Holdorf28-Feb-09 14:34 
I got something working. Here is a sample cache manager and aspx page. Now, all I need is to handle dependicies. Can anyone help?

aspx code:

    protected void Page_Load(object sender, EventArgs e)
    {
        // Create instance of cacheManager
        CacheManager cacheManager = new CacheManager();

        // Create instance of BC_Customer
        BC_Customer bc_Customer = new BC_Customer();

        string[] param1 = { "customers", "stephen", "lisa" };

        // Must be declared as InsertExpression degelate
        cacheManager.InsertInCache(bc_Customer.InsertCustomerName, param1);

        // Make the generic get cache item call must be declared as a QueryExpression delegate
        List<string> cNameList = (List<string>)cacheManager.GetCacheItem(bc_Customer.GetCustomerName, param1);

        DropDownList1.DataSource = cNameList;
        DropDownList1.DataBind();

        string[] param2 = { "products", "Book", "Card" };

        // Create instance of BC_Products
        BC_Products bc_Products = new BC_Products();

        // Must be declared as InsertExpression degelate
        cacheManager.InsertInCache(bc_Products.InsertProductName, param2);


        // Make the generic get cache item call must be declared as a QueryExpression delegate
        List<string> pNameList = (List<string>)cacheManager.GetCacheItem(bc_Products.GetProductName, param2);

        DropDownList2.DataSource = pNameList;
        DropDownList2.DataBind();

    }


Cache manager:


// Main delegate on which all Get requests are based on.
public delegate object QueryExpression(params object[] parameters);

// Main delegate on which all insert requests are based on.
public delegate object InsertExpression(params object[] parameters);

/// <summary>
/// Summary description for CacheManager
/// </summary>
public class CacheManager
{

    public TimeSpan CacheDuration { get; set; }
    private static object syncObject = new object();
    private bool CachingEnabled = true;

    private bool HasKey(string Key)
    {            
        return (HttpContext.Current.Cache[Key] != null);
    }

	private Object CacheItem(string sCacheKey)
    {
        return (Object)HttpRuntime.Cache[sCacheKey];
    }

    public object GetCacheItem(QueryExpression QueryExpression, params object[] param)
    {
        object objCacheItem = null;

        if (!CachingEnabled)
        {
            return objCacheItem;
        }

        if (CacheItem((string) param[0]) != null)
        {
            return CacheItem((string) param[0]);
        }
        else
        {
            lock (syncObject)
            {
                if (CacheItem((string)param[0]) != null)
                {
                    return CacheItem((string) param[0]);
                }
                else
                {
                    Object cacheItem = QueryExpression(param);

                    DateTime expiration = DateTime.Now.Add(new TimeSpan (6000));

                    HttpContext.Current.Cache.Add((string) param[0], (List<string>) cacheItem, null, expiration,
                        TimeSpan.Zero, System.Web.Caching.CacheItemPriority.Default, null);

                    return cacheItem;
                }
            }
        }
    }

    public Object InsertInCache(InsertExpression insertExpression, params object[] param)
    {
        if (HasKey((string) param[0]))
        {
            return CacheItem((string)(param[0]));
        }


        DateTime expiration = DateTime.Now.Add(new TimeSpan (6000));

        HttpContext.Current.Cache.Add((string) param[0], insertExpression(param), null, expiration, 
                        TimeSpan.Zero, System.Web.Caching.CacheItemPriority.Default, null);

        return CacheItem((string)(param[0]));
    }
}


Thanks,


Steve

modified on Saturday, February 28, 2009 10:00 PM

AnswerRe: Cache Manager design problem Pin
Steve Holdorf1-Mar-09 9:53
Steve Holdorf1-Mar-09 9:53 
QuestionReverse engineering the vc++ project Pin
hariakuthota19-Feb-09 22:28
hariakuthota19-Feb-09 22:28 
AnswerRe: Reverse engineering the vc++ project Pin
bobbery19-Feb-09 23:12
bobbery19-Feb-09 23:12 
AnswerRe: Reverse engineering the vc++ project Pin
Han van Roosmalen3-Mar-09 20:55
Han van Roosmalen3-Mar-09 20:55 
QuestionResource Allocation Logic Pin
Nagarajan Mohan18-Feb-09 2:52
Nagarajan Mohan18-Feb-09 2:52 
QuestionDesign question about layers and MVC Pin
Fernando A. Gomez F.14-Feb-09 11:56
Fernando A. Gomez F.14-Feb-09 11:56 
AnswerRe: Design question about layers and MVC Pin
Jonathan Davies18-Feb-09 3:11
Jonathan Davies18-Feb-09 3:11 
Question.net Serializable DTO Pin
mokrala12-Feb-09 6:14
mokrala12-Feb-09 6:14 
QuestionBuilding a relational graph from a large build enlistment Pin
Adam Dare9-Feb-09 18:01
Adam Dare9-Feb-09 18:01 
AnswerRe: Building a relational graph from a large build enlistment Pin
Jonathan Davies18-Feb-09 3:22
Jonathan Davies18-Feb-09 3:22 
GeneralRe: Building a relational graph from a large build enlistment Pin
Adam Dare18-Feb-09 4:44
Adam Dare18-Feb-09 4:44 
GeneralRe: Building a relational graph from a large build enlistment Pin
Jonathan Davies19-Feb-09 3:03
Jonathan Davies19-Feb-09 3:03 
QuestionHow to play an Animation and make video render before logon through credential provider ?(Vista) [modified] Pin
wyc_xiaoben4-Feb-09 15:07
wyc_xiaoben4-Feb-09 15:07 
QuestionWhat pattern should I use? Pin
nickiii3-Feb-09 5:17
nickiii3-Feb-09 5:17 
AnswerRe: What pattern should I use? Pin
Jon Rista3-Feb-09 10:55
Jon Rista3-Feb-09 10:55 
GeneralRe: What pattern should I use? Pin
nickiii3-Feb-09 13:01
nickiii3-Feb-09 13:01 
Questionbus address converter Pin
aswd30-Jan-09 7:46
aswd30-Jan-09 7:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.