Skip to content

Commit

Permalink
add gc info to the README
Browse files Browse the repository at this point in the history
  • Loading branch information
kukymbr committed Jan 22, 2024
1 parent 5cdc854 commit b8105dd
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fc, err := filecache.New(
filecache.InstanceOptions{
PathGenerator: filecache.FilteredKeyPath,
DefaultTTL: time.Hour,
GCDivisor: 10,
GC: filecache.NewIntervalGarbageCollector("/path/to/cache/dir", time.Hour),
},
)
```
Expand Down Expand Up @@ -107,6 +107,18 @@ If there is no error, this doesn't mean the result is found, the `res.Hit()` fun

To iterate through the cached items, use the `Scanner` tool:

### Removing the expired items

The expired cache items are removed by the `GarbageCollector`, assigned to the `FileCache` instance.

There are three types of the `GarbageCollector` adapters:

* `filecache.NewNopGarbageCollector()` — the `GarbageCollector` doing nothing, all the files are kept;
* `filecache.NewProbabilityGarbageCollector()` — the `GarbageCollector` running with the defined probability, used by default;
* `filecache.NewIntervalGarbageCollector()` — the `GarbageCollector` running by the time interval.

See the [gc.go's](gc.go) godocs for more info.

```go
// Initialize the scanner
scanner := filecache.NewScanner(fc.GetPath())
Expand Down

0 comments on commit b8105dd

Please sign in to comment.