cache

package
v0.1.106 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 8, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DEFAULT ...
	DEFAULT = time.Duration(0)
	// FOREVER ...
	FOREVER = time.Duration(-1)
	// CacheMiddlewareKey ...
	CacheMiddlewareKey = "gincontrib.cache"
)
View Source
const (
	CacheExpireShort  = 1 * time.Hour
	CacheExpireMedium = 6 * time.Hour
	CacheExpireLong   = 24 * time.Hour
	CacheExpireExtra  = 7 * 24 * time.Hour

	TMDBKey          = "com.tmdb."
	TVDBKey          = "com.tvdb."
	TraktKey         = "com.trakt."
	LibraryKey       = "library."
	FanartKey        = "fanart."
	OpensubtitlesKey = "osdb."

	TMDBEpisodeKey                 = TMDBKey + "episode.%d.%d.%d.%s"
	TMDBEpisodeExpire              = CacheExpireLong
	TMDBFindKey                    = TMDBKey + "find.%s.%s"
	TMDBFindExpire                 = CacheExpireLong
	TMDBCountriesKey               = TMDBKey + "countries.%s"
	TMDBCountriesExpire            = CacheExpireLong
	TMDBLanguagesKey               = TMDBKey + "languages.%s"
	TMDBLanguagesExpire            = CacheExpireLong
	TMDBMovieImagesKey             = TMDBKey + "movie.%d.images"
	TMDBMovieImagesExpire          = CacheExpireLong
	TMDBMovieByIDKey               = TMDBKey + "movie.%s.%s"
	TMDBMovieByIDExpire            = CacheExpireLong
	TMDBMovieGenresKey             = TMDBKey + "genres.movies.%s"
	TMDBMovieGenresExpire          = CacheExpireLong
	TMDBMoviesIMDBKey              = TMDBKey + "imdb.list.%s.%d.%d"
	TMDBMoviesIMDBExpire           = 24 * time.Hour
	TMDBMoviesIMDBTotalKey         = TMDBKey + "imdb.list.%s.total"
	TMDBMoviesIMDBTotalExpire      = 24 * time.Hour
	TMDBMoviesTopMoviesKey         = TMDBKey + "topmovies.%s.%s.%s.%s.%d.%d"
	TMDBMoviesTopMoviesExpire      = 24 * time.Hour
	TMDBMoviesTopMoviesTotalKey    = TMDBKey + "topmovies.%s.%s.%s.%s.total"
	TMDBMoviesTopMoviesTotalExpire = 24 * time.Hour
	TMDBSeasonKey                  = TMDBKey + "season.%d.%d.%s.%t"
	TMDBSeasonExpire               = CacheExpireLong
	TMDBSeasonImagesKey            = TMDBKey + "show.%d.%d.images"
	TMDBSeasonImagesExpire         = CacheExpireLong
	TMDBShowByIDKey                = TMDBKey + "show.%d.%s"
	TMDBShowByIDExpire             = CacheExpireLong
	TMDBShowImagesKey              = TMDBKey + "show.%d.images"
	TMDBShowImagesExpire           = CacheExpireLong
	TMDBShowGenresKey              = TMDBKey + "genres.shows.%s"
	TMDBShowGenresExpire           = CacheExpireLong
	TMDBShowsTopShowsKey           = TMDBKey + "topshows.%s.%s.%s.%s.%d.%d"
	TMDBShowsTopShowsExpire        = 24 * time.Hour
	TMDBShowsTopShowsTotalKey      = TMDBKey + "topshows.%s.%s.%s.%s.total"
	TMDBShowsTopShowsTotalExpire   = 24 * time.Hour
	TMDBEpisodeImagesKey           = TMDBKey + "show.%d.%d.%d.images"
	TMDBEpisodeImagesExpire        = CacheExpireLong

	TraktActivitiesKey                     = TraktKey + "last_activities.%s"
	TraktActivitiesExpire                  = 30 * 24 * time.Hour
	TraktListActivitiesKey                 = TraktKey + "list_activities.%s.%s"
	TraktListActivitiesExpire              = 30 * 24 * time.Hour
	TraktPausedLastUpdatesKey              = TraktKey + "PausedLastUpdates.%d"
	TraktPausedLastUpdatesExpire           = 30 * 24 * time.Hour
	TraktMovieKey                          = TraktKey + "movie.%s"
	TraktMovieExpire                       = CacheExpireLong
	TraktMovieByTMDBKey                    = TraktKey + "movie.tmdb.%s"
	TraktMovieByTMDBExpire                 = CacheExpireLong
	TraktMoviesByCategoryKey               = TraktKey + "movies.%s.%s.%d"
	TraktMoviesByCategoryExpire            = 24 * time.Hour
	TraktMoviesByCategoryTotalKey          = TraktKey + "movies.%s.total"
	TraktMoviesByCategoryTotalExpire       = 24 * time.Hour
	TraktMoviesWatchlistKey                = TraktKey + "movies.watchlist"
	TraktMoviesWatchlistExpire             = CacheExpireLong
	TraktMoviesCollectionKey               = TraktKey + "movies.collection"
	TraktMoviesCollectionExpire            = CacheExpireLong
	TraktMoviesListKey                     = TraktKey + "movies.list.%s"
	TraktMoviesListExpire                  = CacheExpireExtra
	TraktMoviesCalendarKey                 = TraktKey + "movies.calendar.%s.%s.%d"
	TraktMoviesCalendarAllExpire           = CacheExpireLong
	TraktMoviesCalendarMyExpire            = CacheExpireShort
	TraktMoviesCalendarTotalKey            = TraktKey + "movies.calendar.%s.total"
	TraktMoviesCalendarTotalExpire         = CacheExpireLong
	TraktMoviesWatchedKey                  = TraktKey + "movies.watched"
	TraktMoviesWatchedExpire               = CacheExpireLong
	TraktMoviesPausedKey                   = TraktKey + "movies.paused"
	TraktMoviesPausedExpire                = CacheExpireLong
	TraktShowKey                           = TraktKey + "show.%s"
	TraktShowExpire                        = CacheExpireLong
	TraktShowsByCategoryKey                = TraktKey + "shows.%s.%s.%d"
	TraktShowsByCategoryExpire             = 24 * time.Hour
	TraktShowsByCategoryTotalKey           = TraktKey + "shows.%s.total"
	TraktShowsByCategoryTotalExpire        = 24 * time.Hour
	TraktShowsWatchlistKey                 = TraktKey + "shows.watchlist"
	TraktShowsWatchlistExpire              = CacheExpireLong
	TraktShowsWatchedKey                   = TraktKey + "shows.watched"
	TraktShowsWatchedExpire                = CacheExpireLong
	TraktShowsPausedKey                    = TraktKey + "shows.paused"
	TraktShowsPausedExpire                 = CacheExpireLong
	TraktShowsCollectionKey                = TraktKey + "shows.collection"
	TraktShowsCollectionExpire             = CacheExpireLong
	TraktShowsListKey                      = TraktKey + "shows.list.%s"
	TraktShowsListExpire                   = CacheExpireExtra
	TraktShowsCalendarKey                  = TraktKey + "shows.calendar.%s.%s.%d"
	TraktShowsCalendarAllExpire            = CacheExpireExtra
	TraktShowsCalendarMyExpire             = CacheExpireLong
	TraktShowsCalendarTotalKey             = TraktKey + "shows.calendar.%s.total"
	TraktShowsCalendarTotalExpire          = CacheExpireLong
	TraktShowsHiddenProgressKey            = TraktKey + "shows.hidden.progress"
	TraktShowsHiddenProgressExpire         = CacheExpireLong
	TraktSeasonsKey                        = TraktKey + "seasons.%d"
	TraktSeasonsExpire                     = CacheExpireLong
	TraktSeasonsExtendedKey                = TraktKey + "seasons.%d.extended"
	TraktSeasonsExtendedExpire             = CacheExpireLong
	TraktSeasonKey                         = TraktKey + "season.%d.%d"
	TraktSeasonExpire                      = CacheExpireLong
	TraktEpisodeKey                        = TraktKey + "episode.%d.%d.%d"
	TraktEpisodeExpire                     = CacheExpireLong
	TraktEpisodeByIDKey                    = TraktKey + "episode.id.%s"
	TraktEpisodeByIDExpire                 = CacheExpireLong
	TraktEpisodeByTMDBKey                  = TraktKey + "episode.tmdb.%s"
	TraktEpisodeByTMDBExpire               = CacheExpireLong
	TraktEpisodeByTVDBKey                  = TraktKey + "episode.tvdb.%s"
	TraktEpisodeByTVDBExpire               = CacheExpireLong
	TraktWatchedMoviesKey                  = TraktKey + "movies.watched.list"
	TraktWatchedMoviesExpire               = CacheExpireLong
	TraktWatchedShowsKey                   = TraktKey + "shows.watched.list"
	TraktWatchedShowsExpire                = CacheExpireLong
	TraktWatchedShowsProgressKey           = TraktKey + "progress.watched.%d"
	TraktWatchedShowsProgressExpire        = CacheExpireLong
	TraktWatchedShowsProgressWatchedKey    = TraktKey + "progress.episodes.watched.%d"
	TraktWatchedShowsProgressWatchedExpire = CacheExpireLong
	TraktShowTMDBKey                       = TraktKey + "show.tmdb.%s"
	TraktShowTMDBExpire                    = CacheExpireLong
	TraktShowTVDBKey                       = TraktKey + "show.tvdb.%s"
	TraktShowTVDBExpire                    = CacheExpireLong
	TraktLockedAccountKey                  = TraktKey + "locked.account"
	TraktLockedAccountExpire               = 24 * time.Hour

	TVDBShowByIDKey    = TVDBKey + "show.%d.%s"
	TVDBShowByIDExpire = CacheExpireLong

	FanartMovieByIDKey    = FanartKey + "movie.%d"
	FanartMovieByIDExpire = CacheExpireLong
	FanartShowByIDKey     = FanartKey + "show.%d"
	FanartShowByIDExpire  = CacheExpireLong

	LibraryStateKey               = LibraryKey + "State.%s"
	LibraryStateExpire            = 30 * 24 * time.Hour
	LibraryWatchedPlaycountKey    = LibraryKey + "WatchedLastPlaycount.%s"
	LibraryWatchedPlaycountExpire = 30 * 24 * time.Hour
	LibraryShowsLastUpdatesKey    = LibraryKey + "showsLastUpdates"
	LibraryShowsLastUpdatesExpire = 7 * 24 * time.Hour
	LibraryResolveFileKey         = LibraryKey + "Resolve_File_%s"
	LibraryResolveFileExpire      = 60 * 24 * time.Hour
	LibrarySyncPlaycountKey       = LibraryKey + "SyncLastPlaycount.%s"
	LibrarySyncPlaycountExpire    = 30 * 24 * time.Hour
)

Variables

This section is empty.

Functions

func Cache

func Cache(store CStore, expire time.Duration) gin.HandlerFunc

Cache Middleware

Types

type CStore

type CStore interface {
	Get(key string, value interface{}) error
	Set(key string, value interface{}, expire time.Duration) error
	Add(key string, value interface{}, expire time.Duration) error
	Replace(key string, data interface{}, expire time.Duration) error
	Delete(key string) error
	Increment(key string, data uint64) (uint64, error)
	Decrement(key string, data uint64) (uint64, error)
	Flush() error
}

CStore ...

type DBStore

type DBStore struct {
	// contains filtered or unexported fields
}

func NewDBStore

func NewDBStore() *DBStore

NewDBStore Returns instance of BoltDB backed cache store

func (*DBStore) Add

func (c *DBStore) Add(key string, value interface{}, expires time.Duration) error

Add ...

func (*DBStore) Decrement

func (c *DBStore) Decrement(key string, delta uint64) (uint64, error)

Decrement ...

func (*DBStore) Delete

func (c *DBStore) Delete(key string) error

Delete ...

func (*DBStore) Flush

func (c *DBStore) Flush() error

Flush ...

func (*DBStore) Get

func (c *DBStore) Get(key string, value interface{}) (err error)

Get ...

func (*DBStore) GetBytes

func (c *DBStore) GetBytes(key string) (ret []byte, err error)

GetBytes gets []byte from cache instance

func (*DBStore) Increment

func (c *DBStore) Increment(key string, delta uint64) (uint64, error)

Increment ...

func (*DBStore) Replace

func (c *DBStore) Replace(key string, value interface{}, expires time.Duration) error

Replace ...

func (*DBStore) Set

func (c *DBStore) Set(key string, value interface{}, expires time.Duration) (err error)

Set ...

func (*DBStore) SetBytes

func (c *DBStore) SetBytes(key string, value []byte, expires time.Duration) (err error)

SetBytes stores []byte into cache instance

type DBStoreItem

type DBStoreItem struct {
	Key   string      `json:"key"`
	Value interface{} `json:"value"`
}

type FileStore

type FileStore struct {
	// contains filtered or unexported fields
}

FileStore ...

func NewFileStore

func NewFileStore(path string) *FileStore

NewFileStore ...

func (*FileStore) Add

func (c *FileStore) Add(key string, value interface{}, expires time.Duration) error

Add ...

func (*FileStore) Decrement

func (c *FileStore) Decrement(key string, delta uint64) (uint64, error)

Decrement ...

func (*FileStore) Delete

func (c *FileStore) Delete(key string) error

Delete ...

func (*FileStore) Flush

func (c *FileStore) Flush() error

Flush ...

func (*FileStore) Get

func (c *FileStore) Get(key string, value interface{}) error

Get ...

func (*FileStore) Increment

func (c *FileStore) Increment(key string, delta uint64) (uint64, error)

Increment ...

func (*FileStore) Replace

func (c *FileStore) Replace(key string, value interface{}, expires time.Duration) error

Replace ...

func (*FileStore) Set

func (c *FileStore) Set(key string, value interface{}, expires time.Duration) error

Set ...

type ResponseCache

type ResponseCache struct {
	Status int
	Header http.Header
	Data   []byte
}

ResponseCache ...

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL