Add 'thumbnails/' from commit '2ebf7b2f23af96b3b499c401fe5498a9349403d8'
git-subtree-dir: thumbnails git-subtree-mainline:ccc651a11egit-subtree-split:2ebf7b2f23
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// NewInMemoryStorage creates a new InMemory instance.
|
||||
func NewInMemoryStorage() InMemory {
|
||||
return InMemory{
|
||||
store: make(map[string]map[string][]byte),
|
||||
}
|
||||
}
|
||||
|
||||
// InMemory represents an in memory storage for thumbnails
|
||||
// Can be used during development
|
||||
type InMemory struct {
|
||||
store map[string]map[string][]byte
|
||||
}
|
||||
|
||||
// Get loads the thumbnail from memory.
|
||||
func (s InMemory) Get(username string, key string) []byte {
|
||||
userImages := s.store[username]
|
||||
if userImages == nil {
|
||||
return nil
|
||||
}
|
||||
return s.store[username][key]
|
||||
}
|
||||
|
||||
// Set stores the thumbnail in memory.
|
||||
func (s InMemory) Set(username string, key string, thumbnail []byte) error {
|
||||
if _, ok := s.store[username]; !ok {
|
||||
s.store[username] = make(map[string][]byte)
|
||||
}
|
||||
s.store[username][key] = thumbnail
|
||||
return nil
|
||||
}
|
||||
|
||||
// BuildKey generates a unique key to store and retrieve the thumbnail.
|
||||
func (s InMemory) BuildKey(r Request) string {
|
||||
parts := []string{
|
||||
r.ETag,
|
||||
r.Resolution.String(),
|
||||
strings.Join(r.Types, ","),
|
||||
}
|
||||
return strings.Join(parts, "+")
|
||||
}
|
||||
Reference in New Issue
Block a user