Documentation
¶
Index ¶
- Variables
- func GetCacheKey(req *http.Request) string
- func ParseCacheControl(header string) map[string]string
- func ReconstructCacheControl(cacheControl map[string]string) string
- type CacheConfig
- type CacheItem
- type CacheManager
- type InMemoryCache
- func (c *InMemoryCache) Delete(key string)
- func (c *InMemoryCache) IsCacheableContentType(contentType string) bool
- func (c *InMemoryCache) List() []string
- func (c *InMemoryCache) Read(key string) (CacheItem, bool)
- func (c *InMemoryCache) ReadFromCache(key string) (CacheItem, bool)
- func (c *InMemoryCache) SetItemExpiration(item *CacheItem, cacheControl map[string]string)
- func (c *InMemoryCache) ShouldCache(resp *http.Response, cacheControl map[string]string) bool
- func (c *InMemoryCache) Write(key string, item CacheItem)
- func (c *InMemoryCache) WriteToCache(key string, item CacheItem, cacheControl map[string]string)
- func (c *InMemoryCache) WriteWithDefaultExpiration(key string, item CacheItem)
- func (c *InMemoryCache) WriteWithExpiration(key string, item CacheItem, cacheControl map[string]string)
Constants ¶
This section is empty.
Variables ¶
var Logger = logging.SetupLogging()
Functions ¶
func GetCacheKey ¶
func ParseCacheControl ¶
ParseCacheControl parses the Cache-Control header and returns a map of directives.
func ReconstructCacheControl ¶
ReconstructCacheControl reconstructs the Cache-Control header from a map of directives.
Types ¶
type CacheConfig ¶
CacheConfig holds configuration for the cache, including cacheable MIME types.
type CacheItem ¶
type CacheItem struct { Path string ContentType string Content []byte ContentEncoding string Expiration time.Time CacheControl string }
CacheItem represents an item in the cache.
type CacheManager ¶
type CacheManager interface { Read(key string) (CacheItem, bool) Write(key string, item CacheItem) Delete(key string) List() []string ShouldCache(resp *http.Response, cacheControl map[string]string) bool SetItemExpiration(item *CacheItem, cacheControl map[string]string) IsCacheableContentType(contentType string) bool WriteWithExpiration(key string, item CacheItem, cacheControl map[string]string) WriteWithDefaultExpiration(key string, item CacheItem) }
CacheManager defines the interface for interacting with the cache.
type InMemoryCache ¶
type InMemoryCache struct {
// contains filtered or unexported fields
}
InMemoryCache provides a simple in-memory cache implementation of CacheManager.
func NewInMemoryCache ¶
func NewInMemoryCache(maxSize int, config CacheConfig) *InMemoryCache
NewInMemoryCache creates a new InMemoryCache with a specified maximum size and cache configuration.
func (*InMemoryCache) Delete ¶
func (c *InMemoryCache) Delete(key string)
Delete removes an item from the cache.
func (*InMemoryCache) IsCacheableContentType ¶
func (c *InMemoryCache) IsCacheableContentType(contentType string) bool
IsCacheableContentType checks if the content type is cacheable based on the configuration.
func (*InMemoryCache) List ¶
func (c *InMemoryCache) List() []string
List returns a list of all keys in the cache.
func (*InMemoryCache) Read ¶
func (c *InMemoryCache) Read(key string) (CacheItem, bool)
Read retrieves an item from the cache.
func (*InMemoryCache) ReadFromCache ¶
func (c *InMemoryCache) ReadFromCache(key string) (CacheItem, bool)
ReadFromCache is a convenience function to access cached items. This could be a method of InMemoryCache if it needs to access the cache's internal state.
func (*InMemoryCache) SetItemExpiration ¶
func (c *InMemoryCache) SetItemExpiration(item *CacheItem, cacheControl map[string]string)
SetItemExpiration adjusts the expiration of a cache item based on Cache-Control directives.
func (*InMemoryCache) ShouldCache ¶
ShouldCache decides whether the response should be cached based on Cache-Control directives and the content type, with a default caching policy for cacheable content types.
func (*InMemoryCache) Write ¶
func (c *InMemoryCache) Write(key string, item CacheItem)
Write adds or updates an item in the cache.
func (*InMemoryCache) WriteToCache ¶
func (c *InMemoryCache) WriteToCache(key string, item CacheItem, cacheControl map[string]string)
WriteToCache stores an item in the cache with an optional expiration based on cacheControl directives.
func (*InMemoryCache) WriteWithDefaultExpiration ¶
func (c *InMemoryCache) WriteWithDefaultExpiration(key string, item CacheItem)
Write adds or updates an item in the cache with the default expiration if not set.
func (*InMemoryCache) WriteWithExpiration ¶
func (c *InMemoryCache) WriteWithExpiration(key string, item CacheItem, cacheControl map[string]string)
WriteWithExpiration stores an item in the cache with an expiration time based on cacheControl.