示例#1
0
文件: movie.go 项目: josgilmo/front
// 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
}
示例#2
0
文件: movie.go 项目: josgilmo/front
// 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
}