newsbot-api/services/cacheMonitor.go
James Tombleson eba63c27ef
Youtube source is now working (#5)
* added extra packages to help with parsing

* getting the core built for Youtube collection.  The feed can be pulled and starting to build the article object

* added some tests, reddit will need more love but youtube is starting off with more tests.  Starting to add Rod to pull missing values from the site

* Added rod to work with browser automation

* Moved the config inside the client as they can change within runtime and need to be refreshed on each client creation

* added more features to collect data per video and tests to support them.

* adding the cache and tests

* moved errors to var values at the top

* youtube is now getting collected and tests have been setup

* resolved an issue with the config

* setting up the first interface, its not used yet

* more updates to the cache service. Not finished yet and could see rework

* added logic to monitor Youtube.  Still basic logic that needs to be wired up to the database
2022-04-17 07:25:49 -07:00

39 lines
840 B
Go

package services
import (
"time"
"github.com/jtom38/newsbot/collector/domain/model"
)
type CacheMonitor struct {}
func NewCacheMonitorClient() CacheMonitor {
return CacheMonitor{}
}
func (cm *CacheMonitor) Enable() {
}
// This will be fired off each time an cache a
func (cm *CacheMonitor) FindExpiredEntries() {
now := time.Now()
for index, item := range cacheStorage {
res := now.After(item.Expires)
if res {
cm.removeExpiredEntries(index)
}
}
}
// This will create a new slice and add the valid items to it and ignore the one to be removed.
// The existing cacheStorage will be replaced.
func (cc *CacheMonitor) removeExpiredEntries(arrayEntry int) {
var temp []*model.CacheItem
for index, item := range cacheStorage {
if index == arrayEntry { continue }
temp = append(temp, item)
}
cacheStorage = temp
}