I merged Brian Coca’s branch and tweaked it a little.
As a result, fact caching can now (in abstract) be configured by a “cache_plugin” option in ansible.cfg.
The default plugin is “bypass”, which is not a plugin, and yields the in-memory caching that Ansible uses now.
An implementation of in memory caching that uses the plugin (for test purposes) is called “memory” and can also be tested with ANSIBLE_CACHE_PLUGIN=memory as an environment variable, but this is silly and not something that would be used in production. From basic testing the in-memory version is somewhere between 25-50% slower than the “bypass” version that uses the native “dict” class directly when running unit tests, however, I don’t think this is terribly important.
The next step is to develop a very basic pickle or BSD or sqlite or other implementation, as well as some larger database variants.
I suspect we may overhaul the architecture a little as this was a quick stab at tweaking what Brian did earlier.
What I have done is make the plugin subclass dict, but not require the plugin itself to subclass dict, but only to define some serializer methods.
In some cases, it may make sense to move more things into the plugin, which we can do as we work on things.
https://github.com/ansible/ansible/blob/devel/lib/ansible/cache/init.py
(notice some slight hacks to increase OO efficiency a bit)
https://github.com/ansible/ansible/blob/devel/lib/ansible/cache/memory.py
(the no-op memory implementation)
For those interested in the “schema”, per se, the keys are always the names of the host records, the values are always dictionaries containing the facts for those hosts, so there’s really very little to it.
It would translate very very easily to storage in things like Riak, Redis, MongoDB, etc.
Additional plugins and tuning are quite welcome.