Exemplo n.º 1
0
func (c *Cache) Set(key *datastore.Key, value interface{}) {
	if c == nil {
		return
	}

	c.objs[key.String()] = value
}
Exemplo n.º 2
0
func (c *Cache) Get(key *datastore.Key) interface{} {
	if c == nil {
		return nil
	}

	return c.objs[key.String()]
}
Exemplo n.º 3
0
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
}
Exemplo n.º 4
0
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
}
Exemplo n.º 5
0
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)
}
Exemplo n.º 6
0
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
	}
}
Exemplo n.º 7
0
// 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
}
Exemplo n.º 8
0
// 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())))
}
Exemplo n.º 9
0
Arquivo: model.go Projeto: favclip/qbg
func (p *MemcacheQueryPlugin) Ancestor(ancestor *datastore.Key) {
	p.buf.WriteString(fmt.Sprintf(":!a=%s", ancestor.String()))
}