If you're using CPython (the official Python interpreter), then this is relatively simple. CPython uses a reference counting memory management system, which means that the number of references to an object is kept track of, and when this reaches zero, the object is instantly destroyed. This is a very simplistic and somewhat inefficient approach to garbage collection, as it's usually better to dereference a whole block of memory all at once, since freeing memory takes time; however there are advantages to reference counting. For instance, in CPython, you can do something like this:
lines = open("file.txt").readlines() Because the file object created by "open" is not referenced, it's destroyed instantly afterwards, and the file is closed. In IronPython, which uses the .NET GC, the object isn't destroyed until sometime later when it is more efficient to discard the memory, and hence the file could be left open for a long time. So whilst reference counting is not efficient, it does result in very predictable behaviour.
Essentially, you could create a wrapper class that keeps objects on disk until they are needed, and then expires them after a certain amount of time (perhaps using the "shelve" module as storage). To expire an object, just remove all references to it. You may want to use the weakref module to make sure you don't give out any "real" references that might prevent your objects from being recycled. You could also use the __getattr__ method so that you can access your data like this:
diskcache.commonvar = 10 # gets from in-memory cache (a dict)
diskcache.rarevar += 10 # gets from disk (via shelve), stores in memory cache
... # more stuff
# rarevar hasn't been access for some time,
# so it's removed when diskcache is accessed again:
diskcache.x += 1 # rarevar removed as x is returned