func (c *Cache) Set(key *datastore.Key, value interface{}) { if c == nil { return } c.objs[key.String()] = value }
func (c *Cache) Get(key *datastore.Key) interface{} { if c == nil { return nil } return c.objs[key.String()] }
func lookupCache(ctx context.Context, key datastore.Key) *MaybeError { maybeItem, err := memcache.Get(ctx, key.String()) var result = new(MaybeError) if err != nil { // treat all errors as "cache miss" *result = CacheMiss{} } else { result = jsonToTodoItem(maybeItem.Value) } return result }
func invalidateCache(ctx context.Context, key datastore.Key) *MaybeError { // delete key from memcache err := memcache.Delete(ctx, key.String()) var result = new(MaybeError) if err != nil { *result = E(err.Error()) } else { *result = Ok{} } return result }
func alertAdmins(c context.Context, key *datastore.Key, entity Lockable, reason string) error { sender := "locker@" + appengine.AppID(c) + ".appspot.com" msg := &mail.Message{ Sender: sender, Subject: reason, Body: fmt.Sprintf("key: %s, entity: %#v", key.String(), entity), } return mail.SendToAdmins(c, msg) }
func updateCache(ctx context.Context, key datastore.Key, item TodoItem) { var result = itemToJson(item) switch (*result).(type) { case Blob: blob := ([]byte)((*result).(Blob)) item := memcache.Item{ Key: key.String(), Value: blob, } memcache.Set(ctx, &item) // ignore errors... worst that can happen is we get a cache miss later default: break } }
// overwrite the current lock func (l *Locker) overwriteLock(c context.Context, key *datastore.Key, entity Lockable, requestID string) error { log.Debugf(c, "overwriteLock %s %s", key.String(), requestID) if l.AlertOnOverwrite { if err := alertAdmins(c, key, entity, "Lock overwrite"); err != nil { log.Errorf(c, "failed to send alert email for lock overwrite: %v", err) } } err := storage.RunInTransaction(c, func(tc context.Context) error { if err := storage.Get(tc, key, entity); err != nil { return err } lock := entity.getLock() lock.Timestamp = getTime() lock.RequestID = requestID if _, err := storage.Put(tc, key, entity); err != nil { return err } return nil }, nil) return err }
// hexKey returns a representation of a key k in base 16. // Useful for etags. func hexKey(k *datastore.Key) string { return fmt.Sprintf("%x", md5.Sum([]byte(k.String()))) }
func (p *MemcacheQueryPlugin) Ancestor(ancestor *datastore.Key) { p.buf.WriteString(fmt.Sprintf(":!a=%s", ancestor.String())) }