github.com/mattermosttest/mattermost-server/v5@v5.0.0-20200917143240-9dfa12e121f9/services/cache/provider.go (about) 1 // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. 2 // See LICENSE.txt for license information. 3 4 package cache 5 6 import "time" 7 8 // CacheOptions contains options for initializaing a cache 9 type CacheOptions struct { 10 Size int 11 DefaultExpiry time.Duration 12 Name string 13 InvalidateClusterEvent string 14 } 15 16 // Provider is a provider for Cache 17 type Provider interface { 18 // NewCache creates a new cache with given options. 19 NewCache(opts *CacheOptions) Cache 20 // Connect opens a new connection to the cache using specific provider parameters. 21 Connect() error 22 // Close releases any resources used by the cache provider. 23 Close() error 24 } 25 26 type cacheProvider struct { 27 } 28 29 // NewProvider creates a new CacheProvider 30 func NewProvider() Provider { 31 return &cacheProvider{} 32 } 33 34 // NewCache creates a new cache with given opts 35 func (c *cacheProvider) NewCache(opts *CacheOptions) Cache { 36 return NewLRU(&LRUOptions{ 37 Name: opts.Name, 38 Size: opts.Size, 39 DefaultExpiry: opts.DefaultExpiry, 40 InvalidateClusterEvent: opts.InvalidateClusterEvent, 41 }) 42 } 43 44 // Connect opens a new connection to the cache using specific provider parameters. 45 func (c *cacheProvider) Connect() error { 46 return nil 47 } 48 49 // Close releases any resources used by the cache provider. 50 func (c *cacheProvider) Close() error { 51 return nil 52 }