The simplest way to implement a cache is to use a Dictionary or similar data structure within your class to hold results in memory for successive calls.
public class CachedDatastore
{
private Dictionary<string, object> cache = new Dictionary<string, object>();
public void FindById(string id)
{
if (!cache.ContainsKey(id))
{
var data = GetDataFromDatabase(id);
cache[id] = data;
}
return cache[id];
}
}
This is just a basic example if you want to try to implement something on your own. It does not support cache "eviction" or re-loading data at any time. If you need more advanced features, I'd recommend looking around in the .NET framework for cache classes or other 3rd party libraries.