Calling the third party data source is costly and data only gets updated every 24 hours.
I have written following methods keeping in mind of above instuction but i am not sure is it correct or what more i can do for better performance in terms of caching or how to handle caching in webapis.
///
/// Returns the sorted list of movies
///
/// Collection of Movies
[CacheOutput(ClientTimeSpan = 86400, ServerTimeSpan = 86400)]
public IEnumerable Get()
{
return repository.GetMovies().OrderBy(c => c.MovieId);
}
///
/// Returns a movie
///
/// movieId
/// Movie
[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;
}
Replies
Know the answer? Post it — somebody with the same question will find it here.