aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorPetter Rodhelind <petter.rodhelind@gmail.com>2021-02-21 23:19:34 +0100
committerPetter Rodhelind <petter.rodhelind@gmail.com>2021-02-21 23:19:34 +0100
commit2e86352fa4c5dc5d9b3b2af5d223977cc3109a61 (patch)
treee105e7137166ca241a015ab40ade9fab9c7acfcd /main.go
parentbb1e6b3f9fa33fe018291ccde6fbfd7a48b459cc (diff)
downloadfbfeed-2e86352fa4c5dc5d9b3b2af5d223977cc3109a61.tar.gz
fbfeed-2e86352fa4c5dc5d9b3b2af5d223977cc3109a61.tar.bz2
fbfeed-2e86352fa4c5dc5d9b3b2af5d223977cc3109a61.zip
Cache cleanup on cacheTimeout.
Diffstat (limited to 'main.go')
-rw-r--r--main.go17
1 files changed, 16 insertions, 1 deletions
diff --git a/main.go b/main.go
index 87d40fa..1b93d8d 100644
--- a/main.go
+++ b/main.go
@@ -143,7 +143,7 @@ func fetch(group string) (c *channel, err error) {
url := "https://www.facebook.com/pg/" + group + "/posts/"
- log.Println("Fetching: ", url)
+ log.Println("Fetching:", url)
resp, err := http.Get(url)
if err != nil {
@@ -162,6 +162,21 @@ func fetch(group string) (c *channel, err error) {
}
func main() {
+ // clean the cache when channels have expired
+ go func() {
+ for {
+ time.Sleep(time.Duration(cacheTimeout) * time.Second)
+ for k, c := range cache.v {
+ if time.Now().Sub(c.Time).Seconds() > cacheTimeout {
+ cache.Lock()
+ delete(cache.v, k)
+ cache.Unlock()
+ log.Println("Removed from cache:", k)
+ }
+ }
+ }
+ }()
+
log.Println("Serving: http://localhost:1212")
http.ListenAndServe(":1212", handler{})
}