views:

116

answers:

1

Hi,

I have a combined authorization and menustructure system on our backend. For performance reasons EntLib caching is used in the frontend client (MVC rel 1.0 website, IIS 5.1 local, IIS 6.0 server, no cluster).

Sometimes 'Cache.Contains' will return true, but the contents of the cache is NULL. I know for certain that I filled it correctly, so what can be the problem here?

EDIT: when I set the cache to 1 minute and add the cacheKey 'A_Key', I will see the key coming back when inspecting the CurrentCacheState. When I view CurrentCacheState after 2 minutes, the key is still there. When I execute 'contains', true is returned. When I execute 'contains' again, the cacheKey is gone! Synchronization problem??

Regards, Michel

Excerpt:

if (IntranetCaching.Cache.Contains(cacheKey))
{
    menuItems = (List<BoMenuItem>)IntranetCaching.Cache[cacheKey];
}
else
{
    using (AuthorizationServiceProxyHelper authorizationServiceProxyHelper = new AuthorizationServiceProxyHelper())
    {
        menuItems = authorizationServiceProxyHelper.Proxy.SelectMenuByUserAndApplication(APPNAME, userName, AuthorizationType.ENUM_LOGIN);
        IntranetCaching.Add(cacheKey, menuItems);
    }
}

And the cachehelper:

public static class IntranetCaching
{
    public static ICacheManager Cache { get; private set; }

    static IntranetCaching()
    {
        Cache = CacheFactory.GetCacheManager();
    }

    public static void Add(string key, object value)
    {
        Cache.Add(
            key
            , value
            , CacheItemPriority.Normal
            , null
            , new Microsoft.Practices.EnterpriseLibrary.Caching.Expirations.AbsoluteTime(TimeSpan.FromMinutes(10)));
    }
}
A: 

I got the following response from Avanade (creators of Entlib):

Most likely, the BackgroundScheduler hasn't performed its sweeping yet. If you're going to examine the source code, the Contains method only checks if the specific key is present in the inmemory cache hashtable while on the GetData method, the code first checks if the item has expired, if it has, the item is removed from the cache.

Sarah Urmeneta Global Technology & Solutions Avanade, Inc. [email protected]

That solution is working for me. Still the question remains why you can use 'Contains' when its outcome cannot be used in a sensible way.

Regards, M.

Michel van Engelen