cache

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheStats

type CacheStats struct {
	CachedUsers int
	TotalFeeds  int
}

Stats returns cache statistics for monitoring.

type FeedListCache

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

FeedListCache provides in-memory caching for the list of all user feeds. This dramatically reduces database reads during feed refresh operations by caching the result of GetAllUserFeeds() which is called every hour.

func NewFeedListCache

func NewFeedListCache(ttl time.Duration) *FeedListCache

NewFeedListCache creates a new feed list cache with the specified TTL. Typical TTL is 15-30 minutes to balance freshness with cost savings.

func (*FeedListCache) Get

func (fc *FeedListCache) Get() ([]database.Feed, bool)

Get retrieves the cached feed list if it exists and is not expired. Returns the feeds and true if cache hit, nil and false if cache miss.

func (*FeedListCache) GetStats

func (fc *FeedListCache) GetStats() FeedListCacheStats

GetStats returns current cache statistics.

func (*FeedListCache) Invalidate

func (fc *FeedListCache) Invalidate()

Invalidate clears the cached feed list, forcing a fresh fetch on next request. Use this when users subscribe/unsubscribe from feeds to ensure immediate updates.

func (*FeedListCache) Set

func (fc *FeedListCache) Set(feeds []database.Feed)

Set stores the feed list in the cache with the configured TTL.

type FeedListCacheStats

type FeedListCacheStats struct {
	CachedFeeds int
	IsValid     bool
}

Stats returns cache statistics for monitoring.

type UnreadCache

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

UnreadCache provides in-memory caching for unread article counts with incremental updates. This dramatically reduces database reads by serving cached counts and updating them incrementally when articles are marked as read/unread.

func NewUnreadCache

func NewUnreadCache(ttl time.Duration) *UnreadCache

NewUnreadCache creates a new unread count cache with the specified TTL. Typical TTL is 90-120 seconds for background refresh of counts.

func (*UnreadCache) Get

func (uc *UnreadCache) Get(userID int) (map[int]int, bool)

Get retrieves cached unread counts for a user if they exist and are not expired. Returns the counts and true if cache hit, nil and false if cache miss.

func (*UnreadCache) GetStats

func (uc *UnreadCache) GetStats() CacheStats

GetStats returns current cache statistics.

func (*UnreadCache) Invalidate

func (uc *UnreadCache) Invalidate(userID int)

Invalidate removes cached counts for a user, forcing a fresh fetch on next request. Use this for complex operations where incremental updates are difficult (e.g., batch operations).

func (*UnreadCache) InvalidateAll

func (uc *UnreadCache) InvalidateAll()

InvalidateAll clears the entire cache. Useful for testing or maintenance.

func (*UnreadCache) Set

func (uc *UnreadCache) Set(userID int, counts map[int]int)

Set stores unread counts for a user in the cache with the configured TTL.

func (*UnreadCache) UpdateCount

func (uc *UnreadCache) UpdateCount(userID, feedID int, wasRead, nowRead bool)

UpdateCount incrementally updates the cached count when an article's read status changes. This provides immediate feedback to users while maintaining cache accuracy.

Parameters:

  • userID: The user whose cache to update
  • feedID: The feed containing the article
  • wasRead: Previous read status of the article
  • nowRead: New read status of the article

Jump to

Keyboard shortcuts

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