You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
965 B
54 lines
965 B
package cache |
|
|
|
import ( |
|
"sync" |
|
"time" |
|
) |
|
|
|
// FeedItem represents a cached feed item |
|
type FeedItem struct { |
|
EventID string |
|
Author string |
|
Content string |
|
Time time.Time |
|
Link string |
|
Title string |
|
Summary string |
|
Image string |
|
} |
|
|
|
// FeedCache stores the kind 1 feed |
|
type FeedCache struct { |
|
items []FeedItem |
|
mu sync.RWMutex |
|
lastUpdated time.Time |
|
} |
|
|
|
// NewFeedCache creates a new feed cache |
|
func NewFeedCache() *FeedCache { |
|
return &FeedCache{ |
|
items: make([]FeedItem, 0), |
|
} |
|
} |
|
|
|
// Set updates the feed cache |
|
func (fc *FeedCache) Set(items []FeedItem) { |
|
fc.mu.Lock() |
|
defer fc.mu.Unlock() |
|
fc.items = items |
|
fc.lastUpdated = time.Now() |
|
} |
|
|
|
// Get retrieves feed items |
|
func (fc *FeedCache) Get() []FeedItem { |
|
fc.mu.RLock() |
|
defer fc.mu.RUnlock() |
|
return fc.items |
|
} |
|
|
|
// GetLastUpdated returns when the feed was last updated |
|
func (fc *FeedCache) GetLastUpdated() time.Time { |
|
fc.mu.RLock() |
|
defer fc.mu.RUnlock() |
|
return fc.lastUpdated |
|
}
|
|
|