'Helper for loading data from memcache'

def retrieve(self, key):

    all_pages = memcache.get('__all_pages__')
    if (all_pages is None):
        all_pages = {}
    item = (memcache.get(key) if all_pages.has_key(key) else None)
    if (item is not None):
        return item
    else:
        item = self.data()
        if (not memcache.set(key, item)):
            logging.error(('Memcache    set    failed    on    %s' % key))
        else:
            all_pages[key] = 1
            if (not memcache.set('__all_pages__', all_pages)):
                logging.error('Memcache    set    failed    on    __all_pages__')
    return item
