Esempio n. 1
0
// PopularMovies ...
func PopularMovies() (result tmdb.SearchMovieResult, err error) {
	// Get a hash
	hash := cache.Hash("movie-popular")

	// Check if it is cached
	if cache.IsCached(path, hash) {
		// Get the cached result
		data, err := cache.Get(path, hash)
		if err != nil {
			return result, err
		}
		err = json.Unmarshal(data, &result)
		return result, err
	}

	// Query to the backend
	result, err = tmdb.PopularMovie()
	if err != nil {
		return result, err
	}

	// Cache the result
	json, err := json.Marshal(result)
	if err != nil {
		return result, err
	}
	err = cache.Save(path, hash, string(json))
	return result, err
}
Esempio n. 2
0
// Movie ...
func Movie(id string) (result tmdb.Movie, err error) {
	// Get a hash
	hash := cache.Hash("movie-" + id)

	// Check if it is cached
	if cache.IsCached(path, hash) {

		// Get the cached result
		data, err := cache.Get(path, hash)
		if err != nil {
			return result, err
		}
		err = json.Unmarshal(data, &result)
		return result, err
	}

	// Query to the backend
	result, err = tmdb.GetMovie(id)
	if err != nil {
		return result, err
	}

	// Cache the result
	json, err := json.Marshal(result)
	if err != nil {
		return result, err
	}
	err = cache.Save(path, hash, string(json))

	return result, err
}