Skip to content

Commit

Permalink
control: formatted duration for config trustengine.cache.expiration
Browse files Browse the repository at this point in the history
The `trustengine.cache.expiration` configuration option would accept
durations as number of nanoseconds. Most likely, this was accidental,
all other configuration options for durations accept formatted duration
strings, with unit suffix.

Change `trustengine.cache.expiration` to accept (only) formatted
duration strings.

This is a potentially compatibility breaking change for existing control
service configuration files.
The `trustengine.cache` configuration block is marked as experimental
and is likely not widely used, so no transition mechanism is added.
  • Loading branch information
matzf committed Oct 10, 2023
1 parent 1774cbf commit efa4160
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
6 changes: 2 additions & 4 deletions doc/manuals/control.rst
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,9 @@ considers the following options.

Disable caching entirely.

.. option:: trustengine.cache.expiration = <int> (Default: 60000000000)
.. option:: trustengine.cache.expiration = <duration> (Default: "1m")

Expiration of cached entries in nanoseconds.

**TODO:** this should be changed to accept values in :ref:`duration format <control-conf-duration>`.
Expiration time for cached entries.

.. object:: drkey

Expand Down
11 changes: 6 additions & 5 deletions private/trust/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"github.com/patrickmn/go-cache"

"github.com/scionproto/scion/pkg/private/util"
"github.com/scionproto/scion/private/config"
)

Expand Down Expand Up @@ -47,20 +48,20 @@ func (cfg *Config) ConfigName() string {
}

type Cache struct {
Disable bool `toml:"disable,omitempty"`
Expiration time.Duration `toml:"expiration,omitempty"`
Disable bool `toml:"disable,omitempty"`
Expiration util.DurWrap `toml:"expiration,omitempty"`
}

func (cfg *Cache) New() *cache.Cache {
if cfg.Disable {
return nil
}
return cache.New(cfg.Expiration, time.Minute)
return cache.New(cfg.Expiration.Duration, time.Minute)
}

func (cfg *Cache) InitDefaults() {
if cfg.Expiration == 0 {
cfg.Expiration = defaultExpiration
if cfg.Expiration.Duration == 0 {
cfg.Expiration.Duration = defaultExpiration
}
}

Expand Down

0 comments on commit efa4160

Please sign in to comment.