Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Cache Classes for Non-ASP.NET Apps??

0 views
Skip to first unread message

Jason Harmon

unread,
Jun 22, 2006, 1:20:16 PM6/22/06
to
Does anyone know of a class (third party or otherwise) that implements
caching functionality similar to the "System.Web.Caching.Cache" class for
ASP.NET, but which can be used by non-ASP.NET apps (in my case a Windows
service)?

The System.Web.Caching.Cache class has exactly the functionality I need, but
I can't use it since my application is not a web app.

Any pointers would be helpful.

Thanks.

Jason Harmon


Markus Kling

unread,
Jun 23, 2006, 5:08:42 AM6/23/06
to
You can find a caching implementation within the Microsoft Enterprise
Library beeing available free via
http://www.microsoft.com/downloads/details.aspx?familyid=5A14E870-406B-4F2A-B723-97BA84AE80B5&displaylang=en


"Jason Harmon" <jha...@us.net> schrieb im Newsbeitrag
news:bd6dnYrZmInETAfZ...@adelphia.com...

Jason Harmon

unread,
Jun 23, 2006, 10:06:55 AM6/23/06
to
Thanks a bunch, much appreciated.

-Jason Harmon

"Markus Kling" <markus...@nospam.nospam> wrote in message
news:eDDPhSq...@TK2MSFTNGP03.phx.gbl...

sloan

unread,
Jun 23, 2006, 12:20:03 PM6/23/06
to

You can also implement a "home grown" simple solution using the Singleton
Design Pattern.

This is "per machine" (in winforms) .. not "per application".

You can find the syntax usage at my blog:


But here is some code:

SimpleCacheHolder sch = SimpleCacheHolder.GetInstance();
sch.Add("mykey" , new Exception("use an exception as a demo for any
object");

object o = sch["mykey"];
//o = sch.Remove("mykey"); // Or remove it
if (null!=o)
{
Exception eeeexxxxx = o as Exception;
Console.WriteLine (eeeexxxxx.Message);
}

spaces.msn.com/sholliday/ look for "Web Session Object Holder" or something
like that.

public class SimpleCacheHolder //: IDataStore
{
private static SimpleCacheHolder singletonInstance = null;
private HybridDictionary m_memoryStore = null;
//private Hashtable m_memoryStore = null;

private SimpleCacheHolder( )
{
m_memoryStore = new HybridDictionary(); // Implements IDictionary by
using a ListDictionary while the collection is small, and then switching to
a Hashtable when the collection gets large.
//m_memoryStore = new Hashtable(); // Or go straight for the HashTable
}

/// <summary>
/// Singleton representing Memory store.
/// </summary>
/// <returns></returns>
public static SimpleCacheHolder GetInstance( )
{
if( null == singletonInstance )
{
singletonInstance = new SimpleCacheHolder();
}
return singletonInstance;
}


public void Clear( )
{
m_memoryStore.Clear( );
}

public void Add( string key, object value )
{

if( m_memoryStore.Contains( key ) )
{
m_memoryStore.Remove( key );
}

m_memoryStore.Add( key, value );
}


public object Remove( string key )
{

// see
http://java.sun.com/j2se/1.4.2/docs/api/java/util/Hashtable.html#remove(java.lang.Object)
// for java method, which returns the object you removed, in case
// you want to do something with it

object returnObject = null;
if (null != this.m_memoryStore)
{
if( m_memoryStore.Contains( key ) )
{
returnObject = this.m_memoryStore[key];
m_memoryStore.Remove( key );
}

}
return returnObject;

}

public object this[ string key ]
{
get
{
if( null != m_memoryStore[ key ] )
{
return m_memoryStore[ key ];
}
return null;
}
}

public int Size
{
get
{
if( null != m_memoryStore )
{
return m_memoryStore.Count ;
}
return 0;
}
}

}


"Jason Harmon" <jha...@us.net> wrote in message
news:bd6dnYrZmInETAfZ...@adelphia.com...

0 new messages