You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+56-2Lines changed: 56 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -31,11 +31,11 @@ func main() {
31
31
IPAddress: "",
32
32
// ipbase.com API token
33
33
Token: "YOUR_IPBASE_API_TOKEN",
34
-
// Maximum radius of the geofence in kilometers, only clients less than or equal to this distance will return true with isAddressNearby
34
+
// Maximum radius of the geofence in kilometers, only clients less than or equal to this distance will return true with IsIPAddressNear()
35
35
// 1 kilometer
36
36
Radius: 1.0,
37
37
// Allow 192.X, 172.X, 10.X and loopback addresses
38
-
AllowPrivateIPAddresses: true
38
+
AllowPrivateIPAddresses: true,
39
39
// How long to cache if any ip address is nearby
40
40
CacheTTL: 7 * (24 * time.Hour), // 1 week
41
41
})
@@ -50,3 +50,57 @@ func main() {
50
50
fmt.Println("Address nearby: ", isAddressNearby)
51
51
}
52
52
```
53
+
54
+
## Caching
55
+
56
+
To cache keys indefinitely, set `CacheTTL: -1`
57
+
58
+
### Local (in-memory)
59
+
60
+
By default, the library will use an in-memory cache that will be used to reduce the number of calls to ipbase.com and increase performance. If no `CacheTTL` value is set (`0`), the in-memory cache is disabled.
61
+
62
+
### Persistent
63
+
64
+
If you need a persistent cache to live outside of your application, [Redis](https://redis.io/) is supported by this library. To have the library cache addres proximity using a Redis instance, simply provide a `redis.RedisOptions` struct to `geofence.Config.RedisOptions`. If `RedisOptions` is configured, the in-memory cache will not be used.
65
+
66
+
> Note: Only Redis 7 is currently supported at the time of this writing.
0 commit comments