Beispiel #1
0
func (c *Cache) Get(key string) (resp []byte, ok bool) {
	// Check disk first
	resp, ok = c.disk.Get(key)
	if ok == true {
		log.Debugf("Found %v in disk cache", key)
		return resp, ok
	}
	resp, ok = c.s3.Get(key)
	if ok == true {
		log.Debugf("Found %v in s3 cache: %v", key, s3cache.CacheKeyToObjectKey(key))
		go c.disk.Set(key, resp)
		return resp, ok
	}
	log.Debugf("%v not found in cache: %v", key, s3cache.CacheKeyToObjectKey(key))
	return []byte{}, ok
}
Beispiel #2
0
func (c *Cache) Get(key string) (resp []byte, ok bool) {
	params := &s3.GetObjectInput{
		Bucket: aws.String(c.Bucket),
		Key:    aws.String(CacheKeyToObjectKey(key)),
	}

	object, err := c.S3.GetObject(params)

	if err != nil {
		log.Debugf("Error getting s3 object: %v", err)
		return []byte{}, false
	}

	data, err := ioutil.ReadAll(object.Body)
	if err != nil {
		log.Errorf("Error reading s3 object: %v", err.Error())
		return []byte{}, false
	}
	return data, err == nil
}
Beispiel #3
0
func (c *Cache) Delete(key string) {
	log.Debugf("Deleting key %v on disk and s3: %v", key, s3cache.CacheKeyToObjectKey(key))
	go c.disk.Delete(key)
	go c.s3.Delete(key)
}
Beispiel #4
0
func (c *Cache) Set(key string, resp []byte) {
	log.Debugf("Setting key %v on disk and s3: %v", key, s3cache.CacheKeyToObjectKey(key))
	go c.disk.Set(key, resp)
	go c.s3.Set(key, resp)
}