cache

package
v0.5.1-0...-c0f5f4e Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2025 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package cache provides thread-safe caching with TTL support.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsLikelyBot

func IsLikelyBot(username string) bool

IsLikelyBot checks if a username suggests it's a bot based on common patterns.

Types

type Cache

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

Cache provides thread-safe caching with TTL.

func New

func New(ttl time.Duration) *Cache

New creates a new cache with the specified TTL.

func (*Cache) Get

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

Get retrieves a value from cache if not expired.

func (*Cache) Set

func (c *Cache) Set(key string, value any)

Set stores a value in cache with TTL.

func (*Cache) SetWithTTL

func (c *Cache) SetWithTTL(key string, value any, ttl time.Duration)

SetWithTTL stores a value in cache with custom TTL.

type Entry

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

Entry holds a cached value with expiration.

type UserCache

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

UserCache caches user type information to avoid repeated API calls.

func NewUserCache

func NewUserCache() *UserCache

NewUserCache creates a new user cache.

func (*UserCache) Get

func (uc *UserCache) Get(username string) (*UserInfo, bool)

Get retrieves user info from cache.

func (*UserCache) Set

func (uc *UserCache) Set(username string, userType UserType)

Set stores user info in cache.

func (*UserCache) SetIfNotExists

func (uc *UserCache) SetIfNotExists(username string, userType UserType)

SetIfNotExists stores user info only if not already cached or if we have more definitive info.

type UserInfo

type UserInfo struct {
	Login    string
	UserType UserType
}

UserInfo caches information about a GitHub user.

type UserType

type UserType string

UserType represents the type of GitHub account.

const (
	UserTypeUser UserType = "User"
	UserTypeOrg  UserType = "Organization"
	UserTypeBot  UserType = "Bot"
)

Jump to

Keyboard shortcuts

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