soffes/Cache
소개
Swift caching library
개발 도구측정된 스타 증가
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- 0
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
OriginalCache
A generic caching library for Swift. Cache depends on Foundation.
This is still very much a work in progress.
Usage
Cache provides a simple Cache protocol:
protocol Cache {
associatedtype Element
func get(key key: String, completion: (Element? -> Void))
func set(key key: String, value: Element, completion: (() -> Void)?)
func remove(key key: String, completion: (() -> Void)?)
func removeAll(completion completion: (() -> Void)?)
}
There are two (well actually three, but we'll get there) provided caches:
MemoryCache— Backed by anNSCacheDiskCache— Backed by files on disk usingNSFileManager
Using both of these is exactly the same interface.
MultiCache
There is a third cache provided called MultiCache. This combines caches.
let cache = MultiCache(caches: [memoryCache, diskCache])
cache.set(key: "foo", value: "bar")
This will write to all caches in parallel. When accessing the multi cache, it will go in order. In this example, it will try the memory cache and if there's a miss it will try the disk cache. If it were to find it in the disk cache, it will write it to all previous caches for faster future reads.
Thanks
Thanks to Caleb Davenport for unintentionally inspiring this and lots of help along the way.
관련 프로젝트 살펴보기
불러오는 중…