def Create(
            self,
            cls,
            category=None,
            # Override any of these for a custom configuration.
            start_empty=_unspecified,
            app_version=_unspecified):
        # Resolve namespace components.
        if start_empty is not _unspecified:
            start_empty = bool(start_empty)
        else:
            start_empty = self._start_empty
        if app_version is _unspecified:
            app_version = GetAppVersion()

        # Reserve & and = for namespace separators.
        for component in (category, app_version):
            if component and ('&' in component or '=' in component):
                raise ValueError('%s cannot be used in a namespace')

        namespace = '&'.join('%s=%s' % (key, value)
                             for key, value in (('class', cls.__name__),
                                                ('category', category),
                                                ('app_version', app_version))
                             if value is not None)

        if self._disable_wrappers:
            return self._store_type(namespace, start_empty=start_empty)

        if self._store_type is not None:
            chain = (self._store_type(namespace), )
        else:
            chain = (MemcacheObjectStore(namespace),
                     PersistentObjectStore(namespace))
        return CacheChainObjectStore(chain, start_empty=start_empty)
 def Create(self, category=None, start_empty=False):
     '''Creates a new object store with the top namespace given in the
 constructor with an optional |category| for classes that need multiple
 object stores (e.g. one for stat and one for read).
 '''
     namespace = self._name
     if category is not None:
         assert not any(c.isdigit() for c in category)
         namespace = '%s/%s' % (namespace, category)
     if self._store_type is not None:
         return self._store_type(namespace, start_empty=start_empty)
     return CacheChainObjectStore(
         (MemcacheObjectStore(namespace), PersistentObjectStore(namespace)),
         start_empty=start_empty)
Example #3
0
 def testStartEmpty(self):
     store = CacheChainObjectStore((self._first, self._second, self._third),
                                   start_empty=True)
     # Won't query delegate file systems because it starts empty.
     self.assertEqual(None, store.Get('storage.html').Get())
     self.assertTrue(*self._first.CheckAndReset())
     self.assertTrue(*self._second.CheckAndReset())
     self.assertTrue(*self._third.CheckAndReset())
     # Setting values will set on all delegates, though.
     store.Set('storage.html', 'new content')
     self.assertEqual('new content', store.Get('storage.html').Get())
     self.assertTrue(*self._first.CheckAndReset(set_count=1))
     self.assertTrue(*self._second.CheckAndReset(set_count=1))
     self.assertTrue(*self._third.CheckAndReset(set_count=1))
     self.assertEqual('new content', self._first.Get('storage.html').Get())
     self.assertEqual('new content', self._second.Get('storage.html').Get())
     self.assertEqual('new content', self._third.Get('storage.html').Get())
Example #4
0
 def setUp(self):
     self._first = TestObjectStore('first',
                                   init={
                                       'storage.html': 'storage',
                                   })
     self._second = TestObjectStore('second',
                                    init={
                                        'runtime.html': 'runtime',
                                        'storage.html': 'storage',
                                    })
     self._third = TestObjectStore('third',
                                   init={
                                       'commands.html': 'commands',
                                       'runtime.html': 'runtime',
                                       'storage.html': 'storage',
                                   })
     self._store = CacheChainObjectStore(
         (self._first, self._second, self._third))