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.
C#
/// <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)]
C#
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;
}
Answers
Know the answer? Post it. Somebody with the same question will find it here.