I am caching Get method in webapi with strathweb,now i want to use same cached output in my another webapi method Search.So how to access cached Get result in Search Method?How to find Cache Key to use it in another methods?
[CacheOutput(ClientTimeSpan = 300, ServerTimeSpan = 300)]
public IEnumerable<Movie> Get()
{
return repository.GetEmployees().OrderBy(c => c.MovieId);
}
Rather than using the OutputCache
, you could consider using MemoryCache
to store your results in memory for faster access.
You can store the results in cache (taking example from the following : http://www.allinsight.de/caching-objects-in-net-with-memorycache/
//Get the default MemoryCache to cache objects in memory
private ObjectCache cache; = MemoryCache.Default;
private CacheItemPolicy policy;
public ControllerConstructor()
{
cache = MemoryCache.Default;
policy = new CacheItemPolicy();
policy.AbsoluteExpiration = DateTimeOffset.Now.AddMinutes(30);
}
public IEnumerable<Movie> GetMovieBySearchParameter(string searchstr)
{
if (cache.Get(searchstr) != null)
{
return cache.Get(searchstr) as IEnumerable<Movie>;
}
// Do the search and get the results.
IEnumerable<Movie> result = GetMovies(blah.....);
// Store the results in cache.
cache.Add(searchstr, result, policy);
}
The above is very rough (I don't have VS in front of me right now to try it), but hopefully the core idea comes across.
http://www.allinsight.de/caching-objects-in-net-with-memorycache/