Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: sync cache #35

Merged
merged 15 commits into from
Apr 27, 2016
Merged

Feature: sync cache #35

merged 15 commits into from
Apr 27, 2016

Conversation

vadymmarkov
Copy link
Contributor

Cache is born to be async, so I've decided that there is no place for sync functions in CacheAware protocol, it kinda breaks the whole architecture of the library. But if for some reason you really need to perform cache operations synchronously (on your own risk 😄), there are helpers for that:

SyncHybridCache for HybridCache

let cache = HybridCache(name: "Mix")
let syncCache = SyncHybridCache(cache)

// Add UIImage to cache synchronously
syncCache.add("image", object: UIImage(named: "image.png"))

// Retrieve image from cache synchronously
let image: UIImage? = syncCache.object("image")

// Remove an object from the cache
syncCache.remove("image")

// Clean the cache
syncCache.clear()

HybridCache for type safe Cache

let cache = Cache<UIImage>(name: "ImageCache")
let syncCache = SyncCache(cache)

syncCache.add("image", object: UIImage(named: "image.png"))
let image = syncCache.object("image")
syncCache.remove("image")
syncCache.clear()

This PR also adds source code documentation and this is nice 📖

Fixes #33

@vadymmarkov
Copy link
Contributor Author

Travis is as always 😬

### SyncHybridCache

`Cache` is born to be async, but if for some reason you need to perform cache
operations synchronously, there is a helper for that.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should read;

Cache was born to be async.

@zenangst zenangst merged commit 9174a0b into master Apr 27, 2016
@zenangst zenangst deleted the feature/sync-cache branch April 27, 2016 09:41
@zenangst
Copy link
Contributor

Travis...

@arden
Copy link

arden commented Apr 27, 2016

great

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants