Skip to content

Commit

Permalink
wip...
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanchriswhite committed Dec 10, 2024
1 parent b7d1086 commit 2f5e89c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 17 deletions.
17 changes: 8 additions & 9 deletions pkg/client/query/cache/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@ import (
"time"
)

// EvictionPolicy determines how items are removed when cache is full
type EvictionPolicy string
// EvictionPolicy determines how items are removed when cache is full.
type EvictionPolicy int64

// TODO_IN_THIS_COMMIT: refactor to an enum.
const (
LeastRecentlyUsed EvictionPolicy = "LEAST_RECENTLY_USED"
LeastFrequentlyUsed EvictionPolicy = "LEAST_FREQUENTLY_USED"
FirstInFirstOut EvictionPolicy = "FIRST_IN_FIRST_OUT"
FirstInFirstOut = EvictionPolicy(iota)
LeastRecentlyUsed
LeastFrequentlyUsed
)

// CacheConfig is the configuration options for a cache.
type CacheConfig struct {
// MaxSize is the maximum number of items the cache can hold.
MaxSize int64
// MaxItems is the maximum number of items the cache can hold.
MaxItems int64
// EvictionPolicy is how items should be removed when the cache is full.
EvictionPolicy EvictionPolicy
// TTL is how long items should remain in the cache
Expand Down Expand Up @@ -55,7 +54,7 @@ func WithHistoricalMode(pruneOlderThan int64) CacheOption {
// WithMaxSize sets the maximum size of the cache
func WithMaxSize(size int64) CacheOption {
return func(cfg *CacheConfig) {
cfg.MaxSize = size
cfg.MaxItems = size
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/client/query/cache/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (c *InMemoryCache[T]) Set(key string, value T) error {
return c.SetAtHeight(key, value, c.latestHeight.Load())
}

if c.config.MaxSize > 0 && int64(len(c.items)) >= c.config.MaxSize {
if c.config.MaxItems > 0 && int64(len(c.items)) >= c.config.MaxItems {
c.evict()
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/client/query/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func DefaultParamsQuerierConfig() *ParamsQuerierConfig {
CacheOpts: []cache.CacheOption{
// TODO_IN_THIS_COMMIT: extract to constants.
cache.WithHistoricalMode(100),
// TODO_IN_THIS_COMMIT: reconcile the fact that MaxSize doesn't apply to historical mode...
// TODO_IN_THIS_COMMIT: reconcile the fact that MaxItems doesn't apply to historical mode...
//cache.WithMaxSize(1),
// TODO_IN_THIS_COMMIT: extract to constants.
cache.WithEvictionPolicy(cache.FirstInFirstOut),
Expand Down
10 changes: 4 additions & 6 deletions pkg/client/query/paramsquerier.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ func NewBaseParamsQuerier[P cosmostypes.Msg, Q paramsQuerierIface[P]](
if err := depinject.Inject(
deps,
&querier.clientConn,
&querier.blockQuerier,
); err != nil {
return nil, err
}
Expand All @@ -52,11 +51,10 @@ func NewBaseParamsQuerier[P cosmostypes.Msg, Q paramsQuerierIface[P]](
// It handles parameter caching and chain querying in a generic way, where
// R is the type of the parameters and Q is the type of the query client.
type baseParamsQuerier[P cosmostypes.Msg, Q paramsQuerierIface[P]] struct {
clientConn gogogrpc.ClientConn
queryClient Q
blockQuerier client.BlockQueryClient
paramsCache client.HistoricalQueryCache[P]
config *ParamsQuerierConfig
clientConn gogogrpc.ClientConn
queryClient Q
paramsCache client.HistoricalQueryCache[P]
config *ParamsQuerierConfig
}

// TODO_IN_THIS_COMMIT: update godoc...
Expand Down

0 comments on commit 2f5e89c

Please sign in to comment.