An experimental IndieWeb site built in Go.
1package storage
2
3import (
4 "time"
5
6 "github.com/jellydator/ttlcache/v3"
7 "go.hacdias.com/indielib/indieauth"
8)
9
10var authCache *ttlcache.Cache[string, *indieauth.AuthenticationRequest]
11var nonceCache *ttlcache.Cache[string, string]
12
13func CleanupCaches() {
14 AuthCache().Stop()
15}
16
17func AuthCache() *ttlcache.Cache[string, *indieauth.AuthenticationRequest] {
18 if authCache != nil {
19 return authCache
20 }
21
22 cache := ttlcache.New(
23 ttlcache.WithTTL[string, *indieauth.AuthenticationRequest](10 * time.Minute),
24 )
25
26 go cache.Start()
27
28 authCache = cache
29
30 return cache
31}
32
33func NonceCache() *ttlcache.Cache[string, string] {
34 if nonceCache != nil {
35 return nonceCache
36 }
37
38 cache := ttlcache.New(
39 ttlcache.WithTTL[string, string](5 * time.Minute),
40 )
41
42 go cache.Start()
43
44 nonceCache = cache
45
46 return cache
47}