mementos /

class MementoMetaclass(type):
    Classes that use this caching metaclass will have their instances
    automatically cached based on instantiation-time arguments (i.e. to __init__).
    Super-useful for not repetitively creating expensive-to-create objects.
    cache = {}

    def __call__(self, *args, **kwargs):
        key = (self, ) + args + tuple(kwargs.items())
            return self.cache[key]
        except KeyError:
            instance = type.__call__(self, *args, **kwargs)
            self.cache[key] = instance
            return instance

# Looking to possibility of creating a parametrized metaclass, metaclass
# factory, or similar mecahnism to be able to configure MementoMetaclass on the
# fly. This would provide a mechanism for MementoMetaclass users to stipulate
# what parameters are used as the object-identifying key (currently: all of
# them, in exactly the call signature). Not ready to pull the trigger on that,
# however. Metaclasses are a bit tricky, and must be "done right." 

# Some reading: