omcache.py: avoid a circular reference in log callback to allow gc

The log callback that referenced self._omc_log created a circular reference
to the OMcache object which prevented it from being garbage collected.  This
caused memory and file descriptors to build up if short-lived omcache
objects were created.  Define the actual log function in function local
scope to work around it.
omcache.py: don't use xrange() for python3 compatibility

Also added a free() method for OMcache() to avoid explicitly freeing it in
case the object won't get garbage collected immediately (for example when
using PyPy.)