// NewTTLStore creates and returns a ExpirationCache with a TTLPolicy
508964
func NewTTLStore(keyFunc KeyFunc, ttl time.Duration) Store {
	return &ExpirationCache{
		cacheStorage:     NewThreadSafeStore(Indexers{}, Indices{}),
		keyFunc:          keyFunc,
		clock:            util.RealClock{},
		expirationPolicy: &TTLPolicy{ttl, util.RealClock{}},
	}
}
794693
func NewTree(e StorageEngine, c Config) *Tree {
	return &Tree{eng: e, cfg: c}
}
458782
func newToken(user string, expires time.Time, secret []byte) string {
	if user == "" {
		return ""
	}
	llen := len(user)
	b := make([]byte, llen+tsLen+hashLen)
	// Put expiration time.
	binary.BigEndian.PutUint32(b, uint32(expires.Unix()))
	// Put login.
	copy(b[tsLen:], []byte(user))
	// Calculate and put signature.
	sig := getSignature([]byte(b[:tsLen+llen]), secret)
	copy(b[tsLen+llen:], sig)
	// Base64-encode.
	return base64.URLEncoding.EncodeToString(b)
}
185249
func (s *ExpirableStorageBakeryService) ExpireStorageAfter(t time.Duration) (authentication.ExpirableStorageBakeryService, error) {
	store := s.Store.ExpireAfter(t)
	service, err := bakery.NewService(bakery.NewServiceParams{
		Location: s.Location(),
		Store:    store,
		Key:      s.Key,
		Locator:  s.Locator,
	})
	if err != nil {
		return nil, errors.Trace(err)
	}
	return &ExpirableStorageBakeryService{service, s.Key, store, s.Locator}, nil
}
107970
func (l *Limiter) GetHeaderEntryExpirationTTL() time.Duration {
	l.RLock()
	defer l.RUnlock()
	return l.headerEntryExpirationTTL
}
925126
func NewExpireCache(ttl time.Duration) *ExpireCache {
	return &ExpireCache{
		cache: make(map[interface{}]*expireRecord),
		ttl:   ttl,
	}
}
1232408
func TTL(secsFromCitrusLeafEpoc uint32) uint32 {
	switch secsFromCitrusLeafEpoc {
	// don't convert magic values
	case 0: // when set to don't expire, this value is returned
		return math.MaxUint32
	default:
		// Record may not have expired on server, but delay or clock differences may
		// cause it to look expired on client. Floor at 1, not 0, to avoid old
		// "never expires" interpretation.
		now := time.Now().Unix()
		expiration := int64(CITRUSLEAF_EPOCH + secsFromCitrusLeafEpoc)
		if expiration < 0 || expiration > now {
			return uint32(expiration - now)
		}
		return 1
	}
}
406719
func (t *templateHandler) NewTextTemplate() tpl.TemplateParseFinder {
	t.mu.Lock()
	defer t.mu.Unlock()

	tt := &textTemplate{t: texttemplate.New("")}
	t.extTextTemplates = append(t.extTextTemplates, tt)

	return struct {
		tpl.TemplateParser
		tpl.TemplateLookup
		tpl.TemplateLookupVariant
	}{
		tt,
		tt,
		new(nopLookupVariant),
	}

}
35960
func (store *Store) doSetValue(rtx *libredis.Tx, key string, expiration time.Duration) (bool, error) {
	for i := 0; i < store.MaxRetry; i++ {
		created, err := setValue(rtx, key, expiration)
		if err == nil {
			return created, nil
		}
	}
	return false, errors.New("retry limit exceeded")
}
182577
func NewTUFMetaStorage(m MetaStore) *TUFMetaStorage {
	return &TUFMetaStorage{
		MetaStore:  m,
		cachedMeta: make(map[string]*storedMeta),
	}
}
1161580
func (c *Context) NewTxn(context.Context) error {
	if c.Store == nil {
		return errors.New("store is not set")
	}
	if c.txn.Valid() {
		err := c.txn.Commit(c.ctx)
		if err != nil {
			return errors.Trace(err)
		}
	}

	txn, err := c.Store.Begin()
	if err != nil {
		return errors.Trace(err)
	}
	c.txn.Transaction = txn
	return nil
}
13517
func (lru *TTLRUCache) AddWithExpire(key, val interface{}, expiration time.Time) {
	lru.lock.Lock()
	defer lru.lock.Unlock()

	if etriple, ok := lru.mapping[key]; ok {
		etriple.val = val
		lru.order.MoveToFront(&etriple.orderelement)
		lru.timeorder.MoveToBack(&etriple.timeelement)
		etriple.expiration = expiration
		return
	}

	etriple := lru.triplePool.Get().(*triple)
	etriple.key = key
	etriple.val = val
	etriple.expiration = expiration
	etriple.orderelement.Value = etriple
	etriple.timeelement.Value = etriple
	lru.order.MoveToFront(&etriple.orderelement)
	lru.timeorder.MoveToBack(&etriple.timeelement)
	lru.mapping[key] = etriple

	for lru.order.Len() > lru.capacity {
		element := lru.order.Back()
		etriple := element.Value.(*triple)
		lru.order.Remove(element)
		lru.timeorder.Remove(&etriple.timeelement)
		delete(lru.mapping, etriple.key)
		lru.triplePool.Put(etriple)
	}
}
451559
func (data *TLSData) ToStoreTLSData() *store.EndpointTLSData {
	if data == nil {
		return nil
	}
	result := store.EndpointTLSData{
		Files: make(map[string][]byte),
	}
	if data.CA != nil {
		result.Files[caKey] = data.CA
	}
	if data.Cert != nil {
		result.Files[certKey] = data.Cert
	}
	if data.Key != nil {
		result.Files[keyKey] = data.Key
	}
	return &result
}
222116
func (s *RethinkStore) DeleteExpired() error {
	_, err := r.Table(s.Table).Between(r.MinVal, r.Now(), r.BetweenOpts{Index: "expires"}).Delete().Run(s.Rethink)
	return err
}
896116
func (b *UpdateBuilder) TTL(d time.Duration) *UpdateBuilder {
	b.using.TTL(d)
	return b
}
895047
func NewTagCache(fs fs.FileSystem, service string) *TagCache {
	return &TagCache{fs: fs, service: service}
}
307723
func exptime(ttl uint32) (exp uint32, expired bool) {
	// zero is the special forever case
	if ttl == 0 {
		return 0, false
	}

	now := uint32(time.Now().Unix())

	// The memcached protocol has a... "quirk" where any expiration time over 30
	// days is considered to be a unix timestamp.
	if ttl > realTimeMaxDelta {
		return ttl, (ttl < now)
	}

	// otherwise, this is a normal differential TTL
	return now + ttl, false
}