Skip to content

Commit

Permalink
Sink: add Reset() and Len() to the interface
Browse files Browse the repository at this point in the history
Signed-off-by: Alejandro Mery <[email protected]>
  • Loading branch information
amery committed Mar 13, 2023
1 parent 537c1fe commit e9bf236
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
7 changes: 7 additions & 0 deletions cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,16 @@ type Sink interface {
// of bytes
Bytes() []byte

// Len tells the length of the internally encoded
// representation of the value
Len() int

// Expire returns the time whe this entry will
// be evicted from the Cache
Expire() time.Time

// Reset empties the content of the Sink
Reset()
}

// A Getter loads data for a key.
Expand Down
7 changes: 6 additions & 1 deletion gob.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,15 @@ type GobSink[T any] struct {
// Bytes returns the Gob encoded representation of the object
// in the Sink
func (sink *GobSink[T]) Bytes() []byte {
// TODO: do we need to copy them?
return sink.bytes
}

// Len returns the length of the Gob encoded representation of the
// object in the Sink. 0 if empty.
func (sink *GobSink[T]) Len() int {
return len(sink.bytes)
}

// Expire tells when this object will be evicted from the Cache
func (sink *GobSink[T]) Expire() time.Time {
return sink.e
Expand Down

0 comments on commit e9bf236

Please sign in to comment.