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

isPresentObjectForKey #43

Open
guptakshi16 opened this issue Dec 17, 2013 · 5 comments
Open

isPresentObjectForKey #43

guptakshi16 opened this issue Dec 17, 2013 · 5 comments

Comments

@guptakshi16
Copy link

A api to check if the object is present in the cache will be a great enhancement in this project.
I was thinking of adding a bloom filter to add this functionality. Need feedback if this is already present in some other way.

@Broich
Copy link

Broich commented Apr 13, 2014

+1

@jstn
Copy link
Contributor

jstn commented Apr 13, 2014

EDIT: never mind, see below.

objectForKey: is functionally equivalent, treat any non-nil return value as "object present". In the end it's just an ordinary NSDictionary lookup (there's no difference between accessing an object and seeing if it exists).

http://stackoverflow.com/questions/2784648/how-to-check-if-an-nsdictionary-or-nsmutabledictionary-contains-a-key

https://github.com/tumblr/TMCache/blob/master/TMCache/TMCache.m#L67

@guptakshi16
Copy link
Author

I do not agree on the above. Currently objectForKey returns the object also. The object may be in the file system which means an expensive disk read and unarchive just for the presence check.

Imagine a use case where we want to sync a local TMCache with a remote cache on the server.
Server publishes the current list of files. Client code iterates over the list sent by server and updates based on the server list. In this scenario a presence check is required for all files.

@jstn
Copy link
Contributor

jstn commented Apr 13, 2014

@guptakshi16 you're totally right and I agree, thank you. It should be its own method, and TMDiskCache for its part should just check the presence of the file on disk.

Until that's added I think you could use TMDiskCache::fileURLForKey:block: and pass a block that manually checks for the file with NSURL::checkResourceIsReachableAndReturnError: followed immediately by a call to TMMemoryCache::objectForKey:block:

@mbbischoff mbbischoff reopened this Apr 13, 2014
@irace
Copy link
Contributor

irace commented Dec 4, 2014

This pull request might add the functionality that @guptakshi16 is asking for: #29

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

5 participants