0
Fork 0
mirror of https://github.com/willnorris/imageproxy.git synced 2024-12-16 21:56:43 -05:00
imageproxy/cache/memory.go
2013-12-06 17:40:35 -08:00

41 lines
1.1 KiB
Go

// Copyright 2013 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package cache
import "github.com/willnorris/go-imageproxy/data"
// MemoryCache provides an in-memory Cache implementation.
type MemoryCache struct {
images map[string]*data.Image
}
func NewMemoryCache() *MemoryCache {
return &MemoryCache{
make(map[string]*data.Image),
}
}
func (c MemoryCache) Get(u string) (*data.Image, bool) {
image, ok := c.images[u]
return image, ok
}
func (c MemoryCache) Save(image *data.Image) {
c.images[image.URL] = image
}
func (c MemoryCache) Delete(u string) {
delete(c.images, u)
}