Skip to content

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.

4 participants