2

I'm looking for a library for C/C++/Obj-C to maintain on-disk cache for my objects.

  • There is large number of objects (tens of thousands) and each object is 100+Kb in size
  • Objects are constantly accessed/added, sometimes large group of objects is replaced

Currently I just store each object in separate file but I don't want to create so many files in the filesystem. Is there any library to work with such cache that will use one/several files instead?

pronvit
  • 4,169
  • 1
  • 18
  • 27
  • A compression library would do that. See this [question][1]. [1]: http://stackoverflow.com/questions/230984/compression-api-on-the-iphone – Carey Gregory Oct 12 '11 at 16:20
  • you can create an object which will hold all of your files and make it serialize to save it to binary file, and add to it methods to read and write to file only when needed (it performance is a concern for you) – Pini Cheyni Nov 15 '15 at 15:17

2 Answers2

3

You can make a collection (NSArray, NSSet, NSDictionary) with all your objects and use NSKeyedArchiver/NSKeyedUnarchiver to put that into a single file.

You can also use an SQLite database or CoreData, the advantage being that you wouldn't have to have everything loaded into memory at once if, you just pull objects out of it as needed. Especially if you have (tens of thousands * 100+Kb, which would never fit into memory anyway...).

You could also use C++ serialization libraries (although getting them to work with obj c objects would be tricky..., more recommended for C++ objects) like boost serialization/archive (can output binary, text, xml), again you could use collections (std::list, std::map ...) to store them all into one file.

jbat100
  • 16,757
  • 4
  • 45
  • 70
  • I was thinking about using SQLite but I don't know how well its performance will be with many large objects. Also I don't need SQL, simple key->blob storage is enough. I think there should be some specialized library for caching but I can't find it. – pronvit Oct 12 '11 at 18:16
  • From the SQLite website: The maximum number of bytes in a string or BLOB in SQLite is defined by the preprocessor macro SQLITE_MAX_LENGTH. The default value of this macro is 1 billion (1 thousand million or 1,000,000,000). http://www.sqlite.org/limits.html – jbat100 Oct 12 '11 at 18:33
2

I solved my problem using Tokyo Cabinet library. Works faster than using separate files for each object.

pronvit
  • 4,169
  • 1
  • 18
  • 27