mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-11-24 18:25:57 +03:00
[chore]: Bump codeberg.org/gruf/go-cache/v3 from 3.2.3 to 3.2.5 (#1701)
Bumps codeberg.org/gruf/go-cache/v3 from 3.2.3 to 3.2.5. --- updated-dependencies: - dependency-name: codeberg.org/gruf/go-cache/v3 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This commit is contained in:
parent
c5f61c456b
commit
a3d2774db5
6 changed files with 44 additions and 22 deletions
2
go.mod
2
go.mod
|
@ -5,7 +5,7 @@ go 1.20
|
|||
require (
|
||||
codeberg.org/gruf/go-bytesize v1.0.2
|
||||
codeberg.org/gruf/go-byteutil v1.1.2
|
||||
codeberg.org/gruf/go-cache/v3 v3.2.3
|
||||
codeberg.org/gruf/go-cache/v3 v3.2.5
|
||||
codeberg.org/gruf/go-debug v1.3.0
|
||||
codeberg.org/gruf/go-errors/v2 v2.1.1
|
||||
codeberg.org/gruf/go-fastcopy v1.1.2
|
||||
|
|
4
go.sum
4
go.sum
|
@ -49,8 +49,8 @@ codeberg.org/gruf/go-bytesize v1.0.2/go.mod h1:n/GU8HzL9f3UNp/mUKyr1qVmTlj7+xacp
|
|||
codeberg.org/gruf/go-byteutil v1.0.0/go.mod h1:cWM3tgMCroSzqoBXUXMhvxTxYJp+TbCr6ioISRY5vSU=
|
||||
codeberg.org/gruf/go-byteutil v1.1.2 h1:TQLZtTxTNca9xEfDIndmo7nBYxeS94nrv/9DS3Nk5Tw=
|
||||
codeberg.org/gruf/go-byteutil v1.1.2/go.mod h1:cWM3tgMCroSzqoBXUXMhvxTxYJp+TbCr6ioISRY5vSU=
|
||||
codeberg.org/gruf/go-cache/v3 v3.2.3 h1:HL7UZN9zks2lsYdGTAZONJqVd2jZtj4NgG/1qi8EcJk=
|
||||
codeberg.org/gruf/go-cache/v3 v3.2.3/go.mod h1:up7za8FtNdtttcx6AJ8ffqkrSkXDGTilsd9yJ0IyhfM=
|
||||
codeberg.org/gruf/go-cache/v3 v3.2.5 h1:C+JwTR4uxjuE6qwqB48d3NCRJejsbzxRpfFEBReaViA=
|
||||
codeberg.org/gruf/go-cache/v3 v3.2.5/go.mod h1:up7za8FtNdtttcx6AJ8ffqkrSkXDGTilsd9yJ0IyhfM=
|
||||
codeberg.org/gruf/go-debug v1.3.0 h1:PIRxQiWUFKtGOGZFdZ3Y0pqyfI0Xr87j224IYe2snZs=
|
||||
codeberg.org/gruf/go-debug v1.3.0/go.mod h1:N+vSy9uJBQgpQcJUqjctvqFz7tBHJf+S/PIjLILzpLg=
|
||||
codeberg.org/gruf/go-errors/v2 v2.0.0/go.mod h1:ZRhbdhvgoUA3Yw6e56kd9Ox984RrvbEFC2pOXyHDJP4=
|
||||
|
|
6
vendor/codeberg.org/gruf/go-cache/v3/cache.go
generated
vendored
6
vendor/codeberg.org/gruf/go-cache/v3/cache.go
generated
vendored
|
@ -26,10 +26,10 @@ type Cache[Key comparable, Value any] interface {
|
|||
// Get fetches the value with key from the cache, extending its TTL.
|
||||
Get(key Key) (value Value, ok bool)
|
||||
|
||||
// Add attempts to place the value at key in the cache, doing nothing if a value with this key already exists. Returned bool is success state.
|
||||
// Add attempts to place the value at key in the cache, doing nothing if a value with this key already exists. Returned bool is success state. Calls invalidate callback on success.
|
||||
Add(key Key, value Value) bool
|
||||
|
||||
// Set places the value at key in the cache. This will overwrite any existing value, and call the update callback so. Existing values will have their TTL extended upon update.
|
||||
// Set places the value at key in the cache. This will overwrite any existing value. Existing values will have their TTL extended upon update. Always calls invalidate callback.
|
||||
Set(key Key, value Value)
|
||||
|
||||
// CAS will attempt to perform a CAS operation on 'key', using provided old and new values, and comparator function. Returned bool is success.
|
||||
|
@ -44,7 +44,7 @@ type Cache[Key comparable, Value any] interface {
|
|||
// Invalidate deletes a value from the cache, calling the invalidate callback.
|
||||
Invalidate(key Key) bool
|
||||
|
||||
// Clear empties the cache, calling the invalidate callback.
|
||||
// Clear empties the cache, calling the invalidate callback on each entry.
|
||||
Clear()
|
||||
|
||||
// Len returns the current length of the cache.
|
||||
|
|
7
vendor/codeberg.org/gruf/go-cache/v3/result/cache.go
generated
vendored
7
vendor/codeberg.org/gruf/go-cache/v3/result/cache.go
generated
vendored
|
@ -28,6 +28,7 @@ type Lookup struct {
|
|||
// cache would be in wrapping a database, allowing caching of sql.ErrNoRows.
|
||||
type Cache[Value any] struct {
|
||||
cache ttl.Cache[int64, result[Value]] // underlying result cache
|
||||
invalid func(Value) // store unwrapped invalidate callback.
|
||||
lookups structKeys // pre-determined struct lookups
|
||||
ignore func(error) bool // determines cacheable errors
|
||||
copy func(Value) Value // copies a Value type
|
||||
|
@ -114,7 +115,8 @@ func (c *Cache[Value]) SetInvalidateCallback(hook func(Value)) {
|
|||
if hook == nil {
|
||||
// Ensure non-nil hook.
|
||||
hook = func(Value) {}
|
||||
}
|
||||
} // store hook.
|
||||
c.invalid = hook
|
||||
c.cache.SetInvalidateCallback(func(item *ttl.Entry[int64, result[Value]]) {
|
||||
for _, key := range item.Value.Keys {
|
||||
// Delete key->pkey lookup
|
||||
|
@ -241,6 +243,9 @@ func (c *Cache[Value]) Store(value Value, store func() error) error {
|
|||
// Cache result
|
||||
c.store(result)
|
||||
|
||||
// Call invalidate.
|
||||
c.invalid(value)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
45
vendor/codeberg.org/gruf/go-cache/v3/ttl/ttl.go
generated
vendored
45
vendor/codeberg.org/gruf/go-cache/v3/ttl/ttl.go
generated
vendored
|
@ -19,10 +19,10 @@ type Cache[Key comparable, Value any] struct {
|
|||
// TTL is the cache item TTL.
|
||||
TTL time.Duration
|
||||
|
||||
// Evict is the hook that is called when an item is evicted from the cache, includes manual delete.
|
||||
// Evict is the hook that is called when an item is evicted from the cache.
|
||||
Evict func(*Entry[Key, Value])
|
||||
|
||||
// Invalid is the hook that is called when an item's data in the cache is invalidated.
|
||||
// Invalid is the hook that is called when an item's data in the cache is invalidated, includes Add/Set.
|
||||
Invalid func(*Entry[Key, Value])
|
||||
|
||||
// Cache is the underlying hashmap used for this cache.
|
||||
|
@ -175,7 +175,7 @@ func (c *Cache[K, V]) SetTTL(ttl time.Duration, update bool) {
|
|||
|
||||
if update {
|
||||
// Update existing cache entries with new expiry time
|
||||
c.Cache.Range(0, c.Cache.Len(), func(i int, key K, item *Entry[K, V]) {
|
||||
c.Cache.Range(0, c.Cache.Len(), func(i int, _ K, item *Entry[K, V]) {
|
||||
item.Expiry = item.Expiry.Add(diff)
|
||||
})
|
||||
}
|
||||
|
@ -205,13 +205,14 @@ func (c *Cache[K, V]) Add(key K, value V) bool {
|
|||
c.Lock()
|
||||
defer c.Unlock()
|
||||
|
||||
// If already cached, return
|
||||
if c.Cache.Has(key) {
|
||||
// Check if already exists
|
||||
item, ok := c.Cache.Get(key)
|
||||
if ok {
|
||||
return false
|
||||
}
|
||||
|
||||
// Alloc new item
|
||||
item := c.alloc()
|
||||
item = c.alloc()
|
||||
item.Key = key
|
||||
item.Value = value
|
||||
item.Expiry = time.Now().Add(c.TTL)
|
||||
|
@ -228,6 +229,11 @@ func (c *Cache[K, V]) Add(key K, value V) bool {
|
|||
// Place new item in the map with hook
|
||||
c.Cache.SetWithHook(key, item, hook)
|
||||
|
||||
if c.Invalid != nil {
|
||||
// invalidate old
|
||||
c.Invalid(item)
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
|
@ -240,16 +246,27 @@ func (c *Cache[K, V]) Set(key K, value V) {
|
|||
// Check if already exists
|
||||
item, ok := c.Cache.Get(key)
|
||||
|
||||
if ok {
|
||||
if c.Invalid != nil {
|
||||
// Invalidate existing
|
||||
c.Invalid(item)
|
||||
}
|
||||
} else {
|
||||
if !ok {
|
||||
var hook func(K, *Entry[K, V])
|
||||
|
||||
// Allocate new item
|
||||
item = c.alloc()
|
||||
item.Key = key
|
||||
c.Cache.Set(key, item)
|
||||
|
||||
if c.Evict != nil {
|
||||
// Pass evicted entry to user hook
|
||||
hook = func(_ K, item *Entry[K, V]) {
|
||||
c.Evict(item)
|
||||
}
|
||||
}
|
||||
|
||||
// Place new item in the map with hook
|
||||
c.Cache.SetWithHook(key, item, hook)
|
||||
}
|
||||
|
||||
if c.Invalid != nil {
|
||||
// invalidate old
|
||||
c.Invalid(item)
|
||||
}
|
||||
|
||||
// Update the item value + expiry
|
||||
|
@ -270,7 +287,7 @@ func (c *Cache[K, V]) CAS(key K, old V, new V, cmp func(V, V) bool) bool {
|
|||
}
|
||||
|
||||
if c.Invalid != nil {
|
||||
// Invalidate item
|
||||
// invalidate old
|
||||
c.Invalid(item)
|
||||
}
|
||||
|
||||
|
|
2
vendor/modules.txt
vendored
2
vendor/modules.txt
vendored
|
@ -13,7 +13,7 @@ codeberg.org/gruf/go-bytesize
|
|||
# codeberg.org/gruf/go-byteutil v1.1.2
|
||||
## explicit; go 1.16
|
||||
codeberg.org/gruf/go-byteutil
|
||||
# codeberg.org/gruf/go-cache/v3 v3.2.3
|
||||
# codeberg.org/gruf/go-cache/v3 v3.2.5
|
||||
## explicit; go 1.19
|
||||
codeberg.org/gruf/go-cache/v3
|
||||
codeberg.org/gruf/go-cache/v3/result
|
||||
|
|
Loading…
Reference in a new issue