mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-04 02:04:03 +00:00
## What changed?
<!-- Describe what has changed in this PR -->
Remove license header from every file. Because it is really hard to
follow in this PR here is the summary:
1. License header is removed from all `.go` and `.proto` files
:fireworks::fireworks:🎆.
2. `LICENSE` file in the root directory has only Temporal and Uber
copyrights.
3. 5 other `LICENSE` files added to the packages which have copyrights
different from Temporal and Uber: Datadog, Xargin, "Mat Ryer, Tyler
Bunnell and contributors".
4. `license_file` flag is removed from all code generation tools.
5. `copyright_file` flag is removed from `go:generate mockgen`
directive.
6. All copyright related targets are removed from `Makefile`.
7. Updated Temporal copyright year to 2025 everywhere.
## Why?
<!-- Tell your future self why have you made these changes -->
I double checked with legal department that it is not needed to have
license header in every file. One file per repo is enough. I put all
copyrights to the root `LICENSE` file and removed header from all other
files. Also updated tools and `Makefile`.
87 lines
2.6 KiB
Go
87 lines
2.6 KiB
Go
package cache
|
|
|
|
import (
|
|
"time"
|
|
|
|
"go.temporal.io/server/common/clock"
|
|
)
|
|
|
|
// A Cache is a generalized interface to a cache. See cache.LRU for a specific
|
|
// implementation (bounded cache with LRU eviction)
|
|
type Cache interface {
|
|
// Get retrieves an element based on a key, returning nil if the element
|
|
// does not exist
|
|
Get(key interface{}) interface{}
|
|
|
|
// Put adds an element to the cache, returning the previous element
|
|
Put(key interface{}, value interface{}) interface{}
|
|
|
|
// PutIfNotExist puts a value associated with a given key if it does not exist
|
|
PutIfNotExist(key interface{}, value interface{}) (interface{}, error)
|
|
|
|
// Delete deletes an element in the cache
|
|
Delete(key interface{})
|
|
|
|
// Release decrements the ref count of a pinned element. If the ref count
|
|
// drops to 0, the element can be evicted from the cache.
|
|
Release(key interface{})
|
|
|
|
// Iterator returns the iterator of the cache
|
|
Iterator() Iterator
|
|
|
|
// Size returns current size of the Cache, the size definition is implementation of SizeGetter interface
|
|
// for the entry size, if the entry does not implement SizeGetter interface, the size is 1
|
|
Size() int
|
|
}
|
|
|
|
// Options control the behavior of the cache.
|
|
type Options struct {
|
|
// TTL controls the time-to-live for a given cache entry. Cache entries that
|
|
// are older than the TTL will not be returned.
|
|
TTL time.Duration
|
|
|
|
// Pin prevents in-use objects from getting evicted.
|
|
Pin bool
|
|
|
|
// TimeSource is an optional clock to use for time-skipping and testing. If this is nil, a real clock will be used.
|
|
TimeSource clock.TimeSource
|
|
|
|
OnPut func(val any)
|
|
|
|
OnEvict func(val any)
|
|
}
|
|
|
|
// SimpleOptions provides options that can be used to configure SimpleCache.
|
|
type SimpleOptions struct {
|
|
// RemovedFunc is an optional function called when an element
|
|
// is scheduled for deletion
|
|
RemovedFunc RemovedFunc
|
|
}
|
|
|
|
// RemovedFunc is a type for notifying applications when an item is
|
|
// scheduled for removal from the Cache. If f is a function with the
|
|
// appropriate signature and i is the interface{} scheduled for
|
|
// deletion, Cache calls go f(i)
|
|
type RemovedFunc func(interface{})
|
|
|
|
// Iterator represents the interface for cache iterators.
|
|
type Iterator interface {
|
|
// Close closes the iterator
|
|
// and releases any allocated resources
|
|
Close()
|
|
// HasNext return true if there is more items to be returned
|
|
HasNext() bool
|
|
// Next return the next item
|
|
Next() Entry
|
|
}
|
|
|
|
// Entry represents a key-value entry within the map.
|
|
type Entry interface {
|
|
// Key represents the key
|
|
Key() interface{}
|
|
// Value represents the value
|
|
Value() interface{}
|
|
// CreateTime represents the time when the entry is created
|
|
CreateTime() time.Time
|
|
}
|