Skip to content

Commit

Permalink
readme: add scanner example
Browse files Browse the repository at this point in the history
  • Loading branch information
kukymbr committed Mar 4, 2024
1 parent 8151d0e commit 7facbf0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,17 @@ 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:

```go
scanner := filecache.NewScanner("/path/to/cache/dir")

err := scanner.Scan(func(entry filecache.ScanEntry) error {
// Do something with the found entry...
})
if err := nil {
// Handle the error...
}
```

### Removing the expired items

The expired cache items are removed by the `GarbageCollector`, assigned to the `FileCache` instance.
Expand Down
14 changes: 10 additions & 4 deletions scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@ import (

// ScanEntry is a scanner hit entry.
type ScanEntry struct {
Key string
// Key is a cache item key.
Key string

// CreatedAt is a cache item created-at timestamp.
CreatedAt time.Time
Options *ItemOptions
itemPath string
metaPath string

// Options are the options of the item stored in the cache.
Options *ItemOptions

itemPath string
metaPath string
}

// ScannerHitFn is a function called on every scanner's hit.
Expand Down

0 comments on commit 7facbf0

Please sign in to comment.