func NewStorageInMem(oldestAllowed time.Duration) Storage {
	s := &storageInMem{values: map[parentSoulAndField]*valueWithState{}}
	// Start the purger
	if oldestAllowed > 0 {
		var ctx context.Context
		ctx, s.purgeCancelFn = context.WithCancel(context.Background())
		go func() {
			tick := time.NewTicker(5 * time.Second)
			defer tick.Stop()
			for {
				select {
				case <-ctx.Done():
					return
				case t := <-tick.C:
					oldestStateAllowed := StateFromTime(t.Add(-oldestAllowed))
					s.valueLock.Lock()
					s.valueLock.Unlock()
					for k, v := range s.values {
						if v.state < oldestStateAllowed {
							delete(s.values, k)
						}
					}
				}
			}
		}()
	}
	return s
}
// NewStorageInMem creates an in-memory storage that automatically purges
// values that are older than the given oldestAllowed. If oldestAllowed is 0,
// it keeps all values forever.
NewStorageInMem creates an in-memory storage that automatically purges
values that are older than the given oldestAllowed. If oldestAllowed is 0,
it keeps all values forever.
// NewStorageInMem creates an in - memory storage that automatically purges // values that are older than the given oldestAllowed . If oldestAllowed is 0 // it keeps all values forever .
func NewStorageInMem(oldestAllowed time.Duration) Storage {
	s := &storageInMem{values: map[parentSoulAndField]*valueWithState{}}
	if oldestAllowed > 0 {
		var ctx context.Context
		ctx, s.purgeCancelFn = context.WithCancel(context.Background())
		go func() {
			tick := time.NewTicker(5 * time.Second)
			defer tick.Stop()
			for {
				select {
				case <-ctx.Done():
					return
				case t := <-tick.C:
					oldestStateAllowed := StateFromTime(t.Add(-oldestAllowed))
					s.valueLock.Lock()
					s.valueLock.Unlock()
					for k, v := range s.values {
						if v.state < oldestStateAllowed {
							delete(s.values, k)
						}
					}
				}
			}
		}()
	}
	return s
}
func NewStorageInMem ( oldestAllowed time . Duration ) Storage { s := & storageInMem { values : map [ parentSoulAndField ] * valueWithState { } } if oldestAllowed > 0 { var ctx context . Context ctx , s . purgeCancelFn = context . WithCancel ( context . Background ( ) ) go func ( ) { tick := time . NewTicker ( 5 * time . Second ) defer tick . Stop ( ) for { select { case <- ctx . Done ( ) : return case t := <- tick . C : oldestStateAllowed := StateFromTime ( t . Add ( - oldestAllowed ) ) s . valueLock . Lock ( ) s . valueLock . Unlock ( ) for k , v := range s . values { if v . state < oldestStateAllowed { delete ( s . values , k ) } } } } } ( ) } return s }
NewStorageInMem creates an in-memory storage that automatically purges
values that are older than the given oldestAllowed.
NewStorageInMem creates an in - memory storage that automatically purges values that are older than the given oldestAllowed .
// Start the purger