cache

package
v1.6.5 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultCacheDuration = 24 * time.Hour

DefaultCacheDuration is the default duration for which an item is cached

View Source
var DefaultCacheSize = 100

DefaultCacheSize is the default size of the cache

Functions

This section is empty.

Types

type Cache

type Cache struct {
	Content map[string]Entry `json:"content"`

	Downloaded  SortableArticles `json:"downloaded"`
	OfflineMode bool             `json:"-"`
	// contains filtered or unexported fields
}

Cache handles the caching of feeds and storing downloaded articles

func New

func New(dir string) (*Cache, error)

New creates a new cache store.

func (*Cache) AddToDownloaded

func (c *Cache) AddToDownloaded(item gofeed.Item)

AddToDownloaded adds an item to the downloaded list

func (*Cache) GetArticles

func (c *Cache) GetArticles(url string, ignoreCache bool) (SortableArticles, error)

GetArticles returns an article list using the cache if possible

func (*Cache) GetArticlesBulk

func (c *Cache) GetArticlesBulk(urls []string, ignoreCache bool) SortableArticles

GetArticlesBulk returns a sorted list of articles from all the given urls, ignoring any errors

func (*Cache) GetDownloaded

func (c *Cache) GetDownloaded() SortableArticles

GetDownloaded returns a list of downloaded items

func (*Cache) Load

func (c *Cache) Load() error

Load reads the cache from disk

func (*Cache) RemoveFromDownloaded

func (c *Cache) RemoveFromDownloaded(index int) error

RemoveFromDownloaded removes an item from the downloaded list

func (*Cache) Save

func (c *Cache) Save() error

Save writes the cache to disk

type Entry

type Entry struct {
	Expire   time.Time        `json:"expire"`
	Articles SortableArticles `json:"articles"`
}

Entry is a cache entry

type ReadStatus

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

ReadStatus is a set containing the hashes of the already read articles. We use a struct{} here because it takes up no space in memory. To hash the article, we use the URL of the feed and the title of the article.

func NewReadStatus

func NewReadStatus(dir string) (*ReadStatus, error)

New creates a new ReadStatus set.

func (ReadStatus) IsRead

func (rs ReadStatus) IsRead(url string) bool

IsRead checks if an article is already in the set.

func (*ReadStatus) Load

func (rs *ReadStatus) Load() error

Load reads the cache from disk

func (*ReadStatus) MarkAsRead

func (rs *ReadStatus) MarkAsRead(url string)

MarkAsRead adds an article to the set.

func (*ReadStatus) MarkAsUnread

func (rs *ReadStatus) MarkAsUnread(url string)

MarkAsUnread removes an article from the set.

func (ReadStatus) Save

func (rs ReadStatus) Save() error

Save writes the cache to disk

type SortableArticles

type SortableArticles []gofeed.Item

SortableArticles is a sortable list of articles

func (SortableArticles) Len

func (sa SortableArticles) Len() int

Len returns the length of the item list, needed for sorting

func (SortableArticles) Less

func (sa SortableArticles) Less(a, b int) bool

Less returns true if the item at index i is less than the item at index j, needed for sorting

func (SortableArticles) Swap

func (sa SortableArticles) Swap(a, b int)

Swap swaps the items at index i and j, needed for sorting

Jump to

Keyboard shortcuts

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