=======
 cache
=======

basic manager for quick and dirty caching and editing of links
on a content object. Uses zope3's attr annotation implementation for
storage::

First, fake we'll some content and a filter::

    >>> from wicked import testing
    >>> from wicked.cache import ContentCacheManager
    >>> from wicked.testing.cache import Filter, dummy
    >>> from zope.annotation.interfaces import IAttributeAnnotatable   

    >>> def setup():
    ...     content = dummy({}, iface=IAttributeAnnotatable) 
    ...     content.aq_base = content
    ...     content.getPhysicalPath=lambda : '/you/are/here'.split('/')
    ...     fil = Filter(content)
    ...     fil.section = 'body'
    ...     ccm=ContentCacheManager(fil, content)
    ...     fil.cache=ccm
    ...     return ccm, content
    >>> ccm, content = setup()

Check and make sure the __init__ does the right thing::

    >>> ccm.context == content
    True

Lets manage that hot content cache!  The cache manager takes a tuple:
('string', UID) and some text to cache::

    >>> bob = dummy(dict(getId='bob', UID='bobid', text='some text'))
    >>> dog = dummy(dict(getId='dog', UID='dogid', text='some dog text'))
    >>> ccm.get(bob.getId)

Now some sets::

    >>> ccm.set((dog.getId, dog.UID),  dog.text)
    'some dog text'
    
    >>> ccm.set((bob.getId, bob.UID), bob.text)
    'some text'
    
    >>> ccm.cache_store
    CacheStore '/you/are/here' {'body': Cache '/you/are/here' {'bob': 'bobid', 'dog': 'dogid'}} :: [('bobid', 'some text'), ('dogid', 'some dog text')]

    >>> store = ccm.cache_store
    >>> store._cache['dogid']
    'some dog text'

    >>> store._cache['bobid']
    'some text'

A api friendly get::

    >>> ccm.get('bob')
    'some text'

An unset by slug::

    >>> ccm.unset('bob')
    'some text'

Get with a default::

    >>> _marker = object()
    >>> ccm.get('bob', _marker) is _marker
    True
    
    >>> ccm.get('dog')
    'some dog text'

A null get does not raise(@@change?)::

    >>> ccm.get('billybob')

Finally, make sure uid unsetting works::

    >>> ccm.unset('dogid', use_uid=True)
    'some dog text'

Null unset does not raise(@@change?)::

    >>> ccm.unset('bogusid', use_uid=True)

Finally lets test a remove, wiping all entries for a uid::

    >>> i = ccm.set((dog.getId, dog.UID),  dog.text)
    >>> i = ccm.set(('new address', dog.UID),  'new cache value')
    >>> ccm.cache
    Cache '/you/are/here' {'dog': 'dogid', 'new address': 'dogid'}

    >>> i = ccm.setName('another field')
    >>> i = ccm.set((dog.getId, dog.UID),  dog.text)
    >>> ccm.cache
    Cache '/you/are/here' {'dog': 'dogid'}

    >>> ccm.cache_store
    CacheStore '/you/are/here' {'body': Cache '/you/are/here' {'dog': 'dogid', 'new address': 'dogid'}, 'another field': Cache '/you/are/here' {'dog': 'dogid'}} :: [('bobid', 'some text'), ('dogid', 'some dog text')]

    >>> ccm.remove(dog.UID)
    >>> ccm.cache_store
    C...{'body': Cache '/you/are/here' {}, 'another field': Cache '/you/are/here' {}}...
    
Original get tests::

    >>> ccm, content = setup()
    >>> key = 'bob'
    >>> ccm.get(key)

    >>> _marker = object()
    >>> ccm.get(key, _marker) is _marker
    True
    
    >>> ccm.set((key, 'bobid'), 'some text')
    'some text'
    
    >>> ccm.get(key)
    'some text'



