I have to implement caching in asp.net web api methods because i am accessing data from third party datasource and Calling the third party data source is costly and data only gets updated every 24 hours.So with the help of Strathweb.I have implemented caching like this
/// <summary>
/// Returns the sorted list of movies
/// </summary>
/// <returns>Collection of Movies</returns>
[CacheOutput(ClientTimeSpan = 86400, ServerTimeSpan =86400)]
public IEnumerable<Movie> Get()
{
return repository.GetMovies().OrderBy(c => c.MovieId);
}
/// <summary>
/// Returns a movie
/// </summary>
/// <param name="movie">movieId</param>
/// <returns>Movie</returns>
[CacheOutput(ClientTimeSpan = 86400, ServerTimeSpan = 86400)]
public Movie Get(int movieId)
{
var movie = repository.GetMovieById(movieId);
if (movie == null)
{
var httpResponseMessage = new HttpResponseMessage(HttpStatusCode.NotFound)
{
Content = new StringContent(string.Format("No movie with ID = {0}", movieId)),
ReasonPhrase = "Movie ID Not Found"
};
throw new HttpResponseException(httpResponseMessage);
}
return movie;
}
but in Strathweb,i have seen two attributes one is ClientTimeSpan and Other is ServerTimeSpan.I am not sure when to use ClientTimeSpan and when to use ServerTimeSpan.In the simplest term i want to understand when to use serverside caching and when to use clientside caching and what are the diffrences between both.