Caching outside of txt files

I was wondering how things like memcache and APC cache their data without writing it to txt files, primarily because I’m writing some open source software and want the ability to cache data, but not have files lying around. Obviously as open source software, I don’t want to require they have used PEAR or something similar to use APC. Ya know, robust? :stuck_out_tongue:

Any ideas?


They use memory, RAM. Constantly running like Apache.

If you don’t want to use memcached or APC, then there are only really three options left:

  1. the text files (which you want to avoid)
  2. use a DB (such as SQLite) for caching
  3. use a key-value store (such as MongoDB, although that will also require extra installation)

How I generally do it is to provide APC/ XCache caching if they’re installed, and if not then use a fall-back to file system caching.

Maybe sqlite heap (memory) tables will be more likely installed/ready to be activated than apc?

Why not provide a selection of caching mechanisms for the end-user to choose from? Given some thought, your app’s code needn’t care about which one is being used.

@Salathe - nice one, yes.

Reminds me of the options you see in the PEAR package Log, that might contain some architectural ideas for the OP on how to go about that.

I initially realized I wanted caching because in a globally included file it takes all the settings from a settings table and defines a constant with the setting name and it’s value, and I thought what a waste of time it was to be doing that every page load, when for the most part settings will stay the same (assuming). So it would be great to have a cached copy of them to check against.

As for Salathes remark, that does sound like an optimal idea, allow them to use APC or memcache if they have it installed, otherwise revert to using files, and make the class or functions that retrieve/set cached data use the various methods based on what they choose.