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

Remove object synchronously #33

Closed
namanhams opened this issue Aug 28, 2015 · 8 comments
Closed

Remove object synchronously #33

namanhams opened this issue Aug 28, 2015 · 8 comments

Comments

@namanhams
Copy link

I think it's good if we have an option to remove/clear objects synchronously.
The scenario is that i know the cache is no longer valid and i want to make sure that i don't fetch from it until i completely remove all objects.

@irace
Copy link

irace commented Jan 9, 2016

You could do implement this in user-space using a semaphore or dispatch group, no?

@namanhams
Copy link
Author

You can't. The function to remove/clear objects itself is asynchronous, it will return immediately. It's no point calling that function with a semaphore or distpatch_sync.

@irace
Copy link

irace commented Jan 10, 2016

Ah, sorry. Did not realize there was not even a completion block.

@aschuch
Copy link
Owner

aschuch commented Jan 10, 2016

Do you think a completion block would be sufficient? I am not sure if I want to add sync methods for everything, since that would make the API much larger and more difficult to understand. Since the async part is backed by a serial queue, you should be able to call removeObject and setObject immediately after each other and the queue would make sure to first remove then add the object.

@namanhams
Copy link
Author

@aschuch : i think adding a completion block would be good enough. Actually i prefer this over a separate sync methods.

@irace
Copy link

irace commented Jan 12, 2016

One thing worth considering (and we experienced this with TMCache) is that while async by default with the ability to make synchronous using semaphores or dispatch groups seems like a great idea on paper, it ends up using more threads than synchronous by default with the ability to make asynchronous when needed does. Just food for thought.

@namanhams
Copy link
Author

Actually @irace is right. Make the methods synchronous and wrap it with asynchronous when needed is much easier. That's what i usually do as well

@aschuch
Copy link
Owner

aschuch commented Mar 22, 2016

Please take a look at the WIP draft for AwesomeCache 3.0 #56, which will move towards a sync only API as suggested by @irace and @namanhams. Let me know what you think.

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

No branches or pull requests

3 participants