forked from buildbarn/bb-storage
/
configuration.go
29 lines (27 loc) · 1.05 KB
/
configuration.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package digest
import (
"github.com/buildbarn/bb-storage/pkg/clock"
"github.com/buildbarn/bb-storage/pkg/eviction"
pb "github.com/buildbarn/bb-storage/pkg/proto/configuration/digest"
"github.com/buildbarn/bb-storage/pkg/util"
"github.com/golang/protobuf/ptypes"
)
// NewExistenceCacheFromConfiguration is identical to
// NewExistenceCache(), except that it takes a specification for the
// object to be created from a configuration file message.
func NewExistenceCacheFromConfiguration(configuration *pb.ExistenceCacheConfiguration, keyFormat KeyFormat, name string) (*ExistenceCache, error) {
cacheDuration, err := ptypes.Duration(configuration.CacheDuration)
if err != nil {
return nil, util.StatusWrap(err, "Cache duration")
}
evictionSet, err := eviction.NewSetFromConfiguration(configuration.CacheReplacementPolicy)
if err != nil {
return nil, util.StatusWrap(err, "Cache replacement policy")
}
return NewExistenceCache(
clock.SystemClock,
keyFormat,
int(configuration.CacheSize),
cacheDuration,
eviction.NewMetricsSet(evictionSet, name)), nil
}