https://github.com/storozhukbm/pcache
Cache that tries to keep data local for the goroutine and reduce synchronization overhead, but keep it is safe for concurrent use.
https://github.com/storozhukbm/pcache
cache go golang
Last synced: about 1 year ago
JSON representation
Cache that tries to keep data local for the goroutine and reduce synchronization overhead, but keep it is safe for concurrent use.
- Host: GitHub
- URL: https://github.com/storozhukbm/pcache
- Owner: storozhukBM
- License: mit
- Created: 2020-09-13T23:15:54.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-10-18T12:36:40.000Z (over 5 years ago)
- Last Synced: 2025-04-19T03:53:22.311Z (about 1 year ago)
- Topics: cache, go, golang
- Language: Go
- Homepage:
- Size: 25.4 KB
- Stars: 45
- Watchers: 4
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PCache [](https://github.com/storozhukBM/pcache/actions) [](https://goreportcard.com/report/github.com/storozhukBM/pcache) [](https://codecov.io/gh/storozhukBM/pcache) [](https://pkg.go.dev/github.com/storozhukBM/pcache)
`PCache` Cache that tries to keep data local for the goroutine and reduce synchronization overhead but keep it is safe for concurrent use.
`PCache` does its best to cache items inside and do as little synchronization as possible,
but since it is cache, there is no guarantee that `PCache` won't evict your item after Store.
Due to its implementation specifics, in some edge cases,
PCache can potentially restore previously-stored items after eviction, so please take into account that
**it is possible and valid to observe "old" values of the specific key**.
While this behavior is unconventional, it is totally usable for:
- immutable key-value pairs
- keys that will always resolve into the same value
- cases when it is easy for you to identify that
the value is old and drop it or set to the new one
`PCache` eviction policy is based on GC cycles, so it can evict all items from time to time.
You can limit the size of the cache per goroutine, and `PCache` evicts random items
if I goroutine local cache achieves maxSizePerGoroutine size.
You can also use PCache as a superfast, tiny cache in front of another globally synchronized cache.
## How to use it
You can import it as a library via Go modules or copy-paste `pcache.go` file
it to your project and specify exact types that you need for your cache
to achieve even better performance.
## Benches