localcache

package
v1.7.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 20, 2025 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AuthCache = NewUserAuthCache()

AuthCache is a global cache instance used to store and manage user authentication states efficiently.

View Source
var LocalCache = NewCache(5*time.Minute, 10*time.Minute)

LocalCache is a cache object with a default expiration duration of 5 minutes and a cleanup interval of 10 minutes.

Functions

This section is empty.

Types

type Cache added in v1.7.3

type Cache struct {
	*MemoryShardedCache
}

Cache is a custom in-memory cache implementation (kept for backward compatibility)

func NewCache added in v1.7.3

func NewCache(defaultExpiration, cleanupInterval time.Duration) *Cache

NewCache creates a new cache with the given default expiration and cleanup interval For backward compatibility, it now returns a MemoryShardedCache wrapped in a Cache struct

func (*Cache) Delete added in v1.7.3

func (c *Cache) Delete(k string)

Delete delegates to MemoryShardedCache.Delete

func (*Cache) DeleteExpired added in v1.7.3

func (c *Cache) DeleteExpired()

DeleteExpired delegates to MemoryShardedCache.DeleteExpired

func (*Cache) Get added in v1.7.3

func (c *Cache) Get(k string) (any, bool)

Get delegates to MemoryShardedCache.Get

func (*Cache) Set added in v1.7.3

func (c *Cache) Set(k string, x any, d time.Duration)

Set delegates to MemoryShardedCache.Set

type Item added in v1.7.3

type Item struct {
	Object     any
	Expiration int64
}

Item represents a cached item with expiration time

type MemoryCacheShard added in v1.7.3

type MemoryCacheShard struct {
	// contains filtered or unexported fields
}

MemoryCacheShard represents a single shard of the memory cache

type MemoryShardedCache added in v1.7.3

type MemoryShardedCache struct {
	// contains filtered or unexported fields
}

MemoryShardedCache is a cache that is split into multiple shards to reduce mutex contention

func NewMemoryShardedCache added in v1.7.3

func NewMemoryShardedCache(numShards int, defaultExpiration, cleanupInterval time.Duration) *MemoryShardedCache

NewMemoryShardedCache creates a new sharded cache with the specified number of shards

func (*MemoryShardedCache) Delete added in v1.7.3

func (sc *MemoryShardedCache) Delete(k string)

Delete removes an item from the MemoryShardedCache

func (*MemoryShardedCache) DeleteExpired added in v1.7.3

func (sc *MemoryShardedCache) DeleteExpired()

DeleteExpired removes all expired items from the MemoryShardedCache

func (*MemoryShardedCache) Get added in v1.7.3

func (sc *MemoryShardedCache) Get(k string) (any, bool)

Get retrieves an item from the MemoryShardedCache

func (*MemoryShardedCache) Set added in v1.7.3

func (sc *MemoryShardedCache) Set(k string, x any, d time.Duration)

Set adds an item to the MemoryShardedCache with the given expiration duration

type Resettable added in v1.7.3

type Resettable interface {
	// Reset resets all fields of the object to their zero values
	Reset()
}

Resettable is an interface for objects that can be reset Objects implementing this interface can be reset to their zero values This is useful for objects that are stored in a sync.Pool

type UserAuthCache added in v1.7.1

type UserAuthCache struct {
	// contains filtered or unexported fields
}

UserAuthCache is a cache for authentication results It stores whether a user has been successfully authenticated It can be used by both LDAP and Lua backends

func NewUserAuthCache added in v1.7.1

func NewUserAuthCache() *UserAuthCache

NewUserAuthCache creates a new UserAuthCache

func (*UserAuthCache) Clear added in v1.7.1

func (c *UserAuthCache) Clear()

Clear removes all entries from the cache

func (*UserAuthCache) Delete added in v1.7.1

func (c *UserAuthCache) Delete(username string)

Delete removes an entry from the cache

func (*UserAuthCache) Get added in v1.7.1

func (c *UserAuthCache) Get(username string) (bool, bool)

Get retrieves an entry from the cache Returns the authentication status and whether the entry was found

func (*UserAuthCache) IsAuthenticated added in v1.7.1

func (c *UserAuthCache) IsAuthenticated(username string) bool

IsAuthenticated checks if a user is authenticated Returns true if the user is in the cache and authenticated

func (*UserAuthCache) Set added in v1.7.1

func (c *UserAuthCache) Set(username string, authenticated bool)

Set adds or updates an entry in the cache

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL