diff options
author | Petter Rodhelind <petter.rodhelind@gmail.com> | 2021-02-21 23:19:34 +0100 |
---|---|---|
committer | Petter Rodhelind <petter.rodhelind@gmail.com> | 2021-02-21 23:19:34 +0100 |
commit | 2e86352fa4c5dc5d9b3b2af5d223977cc3109a61 (patch) | |
tree | e105e7137166ca241a015ab40ade9fab9c7acfcd /main.go | |
parent | bb1e6b3f9fa33fe018291ccde6fbfd7a48b459cc (diff) | |
download | fbfeed-2e86352fa4c5dc5d9b3b2af5d223977cc3109a61.tar.gz fbfeed-2e86352fa4c5dc5d9b3b2af5d223977cc3109a61.tar.bz2 fbfeed-2e86352fa4c5dc5d9b3b2af5d223977cc3109a61.zip |
Cache cleanup on cacheTimeout.
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 17 |
1 files changed, 16 insertions, 1 deletions
@@ -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{}) } |