Documentation ¶
Index ¶
- Variables
- type CacheStats
- type FileMeta
- type GetRequest
- type GetURLParams
- type Loader
- type LoadingCache
- func (l *LoadingCache) GetFile(ctx context.Context, req GetRequest) (rd io.ReadCloser, meta FileMeta, err error)
- func (l *LoadingCache) GetURL(ctx context.Context, req GetRequest, params GetURLParams) (url string, meta FileMeta, err error)
- func (l *LoadingCache) Invalidate(ctx context.Context) (invalidated int64, err error)
- func (l *LoadingCache) Run(ctx context.Context) error
- func (l *LoadingCache) Stat(ctx context.Context) (CacheStats, error)
- type Logger
- type Option
- type Options
- type S3
- func (s *S3) Get(ctx context.Context, key string) (io.ReadCloser, error)
- func (s *S3) GetURL(ctx context.Context, key string, params GetURLParams) (string, error)
- func (s *S3) Keys(ctx context.Context) ([]string, error)
- func (s *S3) List(ctx context.Context) ([]FileMeta, error)
- func (s *S3) Meta(ctx context.Context, key string) (FileMeta, error)
- func (s *S3) Put(ctx context.Context, key string, meta FileMeta, rd io.ReadCloser) error
- func (s *S3) Remove(ctx context.Context, key string) error
- func (s *S3) Stat(ctx context.Context) (res StoreStats, err error)
- func (s *S3) UpdateMeta(ctx context.Context, key string, meta FileMeta) error
- type Store
- type StoreMock
- func (mock *StoreMock) Get(ctx context.Context, key string) (io.ReadCloser, error)
- func (mock *StoreMock) GetCalls() []struct{ ... }
- func (mock *StoreMock) GetURL(ctx context.Context, key string, params GetURLParams) (string, error)
- func (mock *StoreMock) GetURLCalls() []struct{ ... }
- func (mock *StoreMock) Keys(ctx context.Context) ([]string, error)
- func (mock *StoreMock) KeysCalls() []struct{ ... }
- func (mock *StoreMock) List(ctx context.Context) ([]FileMeta, error)
- func (mock *StoreMock) ListCalls() []struct{ ... }
- func (mock *StoreMock) Meta(ctx context.Context, key string) (FileMeta, error)
- func (mock *StoreMock) MetaCalls() []struct{ ... }
- func (mock *StoreMock) Put(ctx context.Context, key string, meta FileMeta, rd io.ReadCloser) error
- func (mock *StoreMock) PutCalls() []struct{ ... }
- func (mock *StoreMock) Remove(ctx context.Context, key string) error
- func (mock *StoreMock) RemoveCalls() []struct{ ... }
- func (mock *StoreMock) Stat(ctx context.Context) (StoreStats, error)
- func (mock *StoreMock) StatCalls() []struct{ ... }
- func (mock *StoreMock) UpdateMeta(ctx context.Context, key string, meta FileMeta) error
- func (mock *StoreMock) UpdateMetaCalls() []struct{ ... }
- type StoreStats
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("not found")
ErrNotFound represents a not found error.
Functions ¶
This section is empty.
Types ¶
type CacheStats ¶ added in v0.2.0
type CacheStats struct { Hits int64 Misses int64 Errors int64 StoreStats }
CacheStats represent stat values.
type FileMeta ¶ added in v0.1.1
type FileMeta struct { Name string Mime string // Meta maintains additional data about the file. // Note: some metadata keys with leading underscore are reserved by fcache. Meta map[string]string // Size might not be provided when loading file, though it might be useful // for some cache implementations, like S3 as it runs streaming multipart // method, if size is provided Size int64 // store stat fields Key string CreatedAt time.Time }
FileMeta represent information about the file.
type GetRequest ¶ added in v0.5.0
GetRequest defines parameters to get file.
type GetURLParams ¶ added in v0.3.0
GetURLParams describes additional parameters, besides key, to form a signed URL.
type LoadingCache ¶ added in v0.2.0
type LoadingCache struct { Store Options CacheStats // contains filtered or unexported fields }
LoadingCache is a wrapper for Store, which removes file at their TTL. Only files, added by GetFile and GetURL methods will be removed.
func NewLoadingCache ¶ added in v0.2.0
func NewLoadingCache(backend Store, opts ...Option) *LoadingCache
NewLoadingCache makes new instance of LoadingCache.
func (*LoadingCache) GetFile ¶ added in v0.2.0
func (l *LoadingCache) GetFile(ctx context.Context, req GetRequest) (rd io.ReadCloser, meta FileMeta, err error)
GetFile gets the file from cache or loads it, if absent.
func (*LoadingCache) GetURL ¶ added in v0.2.0
func (l *LoadingCache) GetURL(ctx context.Context, req GetRequest, params GetURLParams) (url string, meta FileMeta, err error)
GetURL returns the URL from the cache backend.
func (*LoadingCache) Invalidate ¶ added in v0.5.0
func (l *LoadingCache) Invalidate(ctx context.Context) (invalidated int64, err error)
Invalidate invalidates expired cache items. Used for tests.
func (*LoadingCache) Run ¶ added in v0.2.0
func (l *LoadingCache) Run(ctx context.Context) error
Run runs invalidation goroutine. It will check for files TTL expiration and, if it expires, removes it manually.
func (*LoadingCache) Stat ¶ added in v0.2.0
func (l *LoadingCache) Stat(ctx context.Context) (CacheStats, error)
Stat returns cache stats
type Logger ¶
type Logger interface {
Printf(format string, args ...interface{})
}
Logger defines a single method for logging in caches.
type Option ¶
type Option func(*Options)
Option is a function to apply options.
func WithInvalidationPeriod ¶
WithInvalidationPeriod sets the period between cache's checks for expired items. Useful for caches, like S3. No manual invalidation by default.
func WithLogger ¶
WithLogger sets logger for cache. `log` package is used by default.
type Options ¶
type Options struct { Log Logger // InvalidatePeriod sets the time for checking cache for expired items. // Zero means "no invalidation", i.e. backend invalidates items by its own. InvalidatePeriod time.Duration // ExtendTTL sets whether cache should extend TTL of cached items on hit. ExtendTTL bool }
Options defines cache options.
type S3 ¶
type S3 struct {
// contains filtered or unexported fields
}
S3 implements Cache for S3.
func (*S3) Get ¶ added in v0.2.0
Get gets the file from cache or loads it, if absent. NOTE: if file under this key is not present in S3, this method WILL NOT return a NotFound error, instead, it will return a reader, which will return error when there will be an attempt to read.
type Store ¶ added in v0.2.0
type Store interface { Meta(ctx context.Context, key string) (FileMeta, error) UpdateMeta(ctx context.Context, key string, meta FileMeta) error Get(ctx context.Context, key string) (rd io.ReadCloser, err error) GetURL(ctx context.Context, key string, params GetURLParams) (url string, err error) Put(ctx context.Context, key string, meta FileMeta, rd io.ReadCloser) error Remove(ctx context.Context, key string) error Stat(ctx context.Context) (StoreStats, error) Keys(ctx context.Context) ([]string, error) List(ctx context.Context) ([]FileMeta, error) }
Store defines methods that the backend store should implement
type StoreMock ¶ added in v0.2.0
type StoreMock struct { // GetFunc mocks the Get method. GetFunc func(ctx context.Context, key string) (io.ReadCloser, error) // GetURLFunc mocks the GetURL method. GetURLFunc func(ctx context.Context, key string, params GetURLParams) (string, error) // KeysFunc mocks the Keys method. KeysFunc func(ctx context.Context) ([]string, error) // ListFunc mocks the List method. ListFunc func(ctx context.Context) ([]FileMeta, error) // MetaFunc mocks the Meta method. MetaFunc func(ctx context.Context, key string) (FileMeta, error) // PutFunc mocks the Put method. PutFunc func(ctx context.Context, key string, meta FileMeta, rd io.ReadCloser) error // RemoveFunc mocks the Remove method. RemoveFunc func(ctx context.Context, key string) error // StatFunc mocks the Stat method. StatFunc func(ctx context.Context) (StoreStats, error) // UpdateMetaFunc mocks the UpdateMeta method. UpdateMetaFunc func(ctx context.Context, key string, meta FileMeta) error // contains filtered or unexported fields }
StoreMock is a mock implementation of Store.
func TestSomethingThatUsesStore(t *testing.T) { // make and configure a mocked Store mockedStore := &StoreMock{ GetFunc: func(ctx context.Context, key string) (io.ReadCloser, error) { panic("mock out the Get method") }, GetURLFunc: func(ctx context.Context, key string, params GetURLParams) (string, error) { panic("mock out the GetURL method") }, KeysFunc: func(ctx context.Context) ([]string, error) { panic("mock out the Keys method") }, ListFunc: func(ctx context.Context) ([]FileMeta, error) { panic("mock out the List method") }, MetaFunc: func(ctx context.Context, key string) (FileMeta, error) { panic("mock out the Meta method") }, PutFunc: func(ctx context.Context, key string, meta FileMeta, rd io.ReadCloser) error { panic("mock out the Put method") }, RemoveFunc: func(ctx context.Context, key string) error { panic("mock out the Remove method") }, StatFunc: func(ctx context.Context) (StoreStats, error) { panic("mock out the Stat method") }, UpdateMetaFunc: func(ctx context.Context, key string, meta FileMeta) error { panic("mock out the UpdateMeta method") }, } // use mockedStore in code that requires Store // and then make assertions. }
func (*StoreMock) GetCalls ¶ added in v0.2.0
GetCalls gets all the calls that were made to Get. Check the length with:
len(mockedStore.GetCalls())
func (*StoreMock) GetURLCalls ¶ added in v0.2.0
func (mock *StoreMock) GetURLCalls() []struct { Ctx context.Context Key string Params GetURLParams }
GetURLCalls gets all the calls that were made to GetURL. Check the length with:
len(mockedStore.GetURLCalls())
func (*StoreMock) KeysCalls ¶ added in v0.2.0
KeysCalls gets all the calls that were made to Keys. Check the length with:
len(mockedStore.KeysCalls())
func (*StoreMock) ListCalls ¶ added in v0.2.0
ListCalls gets all the calls that were made to List. Check the length with:
len(mockedStore.ListCalls())
func (*StoreMock) MetaCalls ¶ added in v0.2.0
MetaCalls gets all the calls that were made to Meta. Check the length with:
len(mockedStore.MetaCalls())
func (*StoreMock) PutCalls ¶ added in v0.2.0
func (mock *StoreMock) PutCalls() []struct { Ctx context.Context Key string Meta FileMeta Rd io.ReadCloser }
PutCalls gets all the calls that were made to Put. Check the length with:
len(mockedStore.PutCalls())
func (*StoreMock) RemoveCalls ¶ added in v0.2.0
RemoveCalls gets all the calls that were made to Remove. Check the length with:
len(mockedStore.RemoveCalls())
func (*StoreMock) Stat ¶ added in v0.2.0
func (mock *StoreMock) Stat(ctx context.Context) (StoreStats, error)
Stat calls StatFunc.
func (*StoreMock) StatCalls ¶ added in v0.2.0
StatCalls gets all the calls that were made to Stat. Check the length with:
len(mockedStore.StatCalls())
func (*StoreMock) UpdateMeta ¶ added in v0.5.0
UpdateMeta calls UpdateMetaFunc.
type StoreStats ¶ added in v0.2.0
StoreStats represents stats of the backend store.