Example #1
0
func setToCache(cache ybc.Cacher, key []byte, flags uint32, expiration time.Duration, size int) *ybc.SetTxn {
	size += binary.Size(&flags)
	txn, err := cache.NewSetTxn(key, size, expiration)
	if err != nil {
		log.Printf("Error in Cache.NewSetTxn() for key=[%s], size=[%d], expiration=[%s]: [%s]", key, size, expiration, err)
		return nil
	}
	binaryWrite(txn, &flags, "flags")
	return txn
}
Example #2
0
func cSetToCache(cache ybc.Cacher, key []byte, size int, flags uint32, expiration time.Duration, etag uint64, validateTtl uint32) *ybc.SetTxn {
	size += binary.Size(&etag) + binary.Size(&validateTtl) + binary.Size(&flags)
	txn, err := cache.NewSetTxn(key, size, expiration)
	if err != nil {
		log.Printf("Error in Cache.NewSetTxn() for key=[%s], size=[%d], expiration=[%s]: [%s]", key, size, expiration, err)
		return nil
	}
	binaryWrite(txn, &etag, "etag")
	binaryWrite(txn, &validateTtl, "validateTtl")
	binaryWrite(txn, &flags, "flags")
	return txn
}
Example #3
0
func writeItemMetadata(cache ybc.Cacher, key []byte, size int, ttl time.Duration, etag uint64, validateTtl uint32, flags uint32) *ybc.SetTxn {
	validateExpiration64 := uint64(time.Now().Add(time.Duration(validateTtl) * time.Millisecond).UnixNano())

	size += binary.Size(&etag) + binary.Size(&validateTtl) + binary.Size(flags) + binary.Size(&validateExpiration64)
	txn, err := cache.NewSetTxn(key, size, ttl)
	if err != nil {
		log.Printf("Unexpected error in Cache.NewSetTxn(size=%d): [%s]", size, err)
		return nil
	}

	binaryWrite(txn, &etag, "etag")
	binaryWrite(txn, &validateTtl, "validateTtl")
	binaryWrite(txn, &flags, "flags")
	binaryWrite(txn, &validateExpiration64, "validateExpiration")

	return txn
}
Example #4
0
func startSetTxn(cache ybc.Cacher, key []byte, flags uint32, expiration time.Duration, size int) *ybc.SetTxn {
	casid := getCasid()
	size += casidSize + flagsSize
	txn, err := cache.NewSetTxn(key, size, expiration)
	if err != nil {
		log.Printf("Error in Cache.NewSetTxn() for key=[%s], size=[%d], expiration=[%s]: [%s]", key, size, expiration, err)
		return nil
	}

	var buf [casidSize + flagsSize]byte
	binary.LittleEndian.PutUint64(buf[:casidSize], casid)
	binary.LittleEndian.PutUint32(buf[casidSize:], flags)
	n, err := txn.Write(buf[:])
	if err != nil {
		log.Fatalf("Error in SetTxn.Write(): [%s]", err)
	}
	if n != len(buf) {
		log.Fatalf("Unexpected result returned from SetTxn.Write(): %d. Expected %d", n, len(buf))
	}
	return txn
}
Example #5
0
func writeItemMetadata(cache ybc.Cacher, key []byte, size int, casid uint64, flags, validateTtl uint32) *ybc.SetTxn {
	validateExpiration64 := uint64(time.Now().Add(time.Duration(validateTtl) * time.Millisecond).UnixNano())

	size += metadataSize
	txn, err := cache.NewSetTxn(key, size, ybc.MaxTtl)
	if err != nil {
		log.Printf("Unexpected error in Cache.NewSetTxn(size=%d): [%s]", size, err)
		return nil
	}

	var buf [metadataSize]byte
	binary.LittleEndian.PutUint64(buf[:casidSize], casid)
	binary.LittleEndian.PutUint32(buf[casidSize:], flags)
	binary.LittleEndian.PutUint32(buf[casidSize+flagsSize:], validateTtl)
	binary.LittleEndian.PutUint64(buf[casidSize+flagsSize+validateTtlSize:], validateExpiration64)
	n, err := txn.Write(buf[:])
	if err != nil {
		log.Fatalf("Error in SetTxn.Write(): [%s]", err)
	}
	if n != len(buf) {
		log.Fatalf("Unexpected result returned from SetTxn.Write(): %d. Expected %d", n, len(buf))
	}
	return txn
}