Esempio n. 1
0
    def __init__(self, cache_manager):
        """Constructor.

    Args:
      cache_manager: local cache with distributed invalidation.
    """
        self.user_tbl = sql.SQLTableManager(USER_TABLE_NAME)
        self.userprefs_tbl = sql.SQLTableManager(USERPREFS_TABLE_NAME)
        self.dismissedcues_tbl = sql.SQLTableManager(DISMISSEDCUES_TABLE_NAME)
        self.hotlistvisithistory_tbl = sql.SQLTableManager(
            HOTLISTVISITHISTORY_TABLE_NAME)
        self.linkedaccount_tbl = sql.SQLTableManager(LINKEDACCOUNT_TABLE_NAME)
        self.linkedaccountinvite_tbl = sql.SQLTableManager(
            LINKEDACCOUNTINVITE_TABLE_NAME)

        # Like a dictionary {user_id: email}
        self.email_cache = caches.RamCache(cache_manager,
                                           'user',
                                           max_size=50000)

        # Like a dictionary {email: user_id}.
        # This will never invaidate, and it doesn't need to.
        self.user_id_cache = caches.RamCache(cache_manager,
                                             'user',
                                             max_size=50000)

        # Like a dictionary {user_id: user_pb}
        self.user_2lc = UserTwoLevelCache(cache_manager, self)

        # Like a dictionary {user_id: userprefs}
        self.userprefs_2lc = UserPrefsTwoLevelCache(cache_manager, self)
Esempio n. 2
0
 def MakeCache(self, kind, max_size=None, use_value_centric_cache=False):
     """Make a new cache and register it for future invalidations."""
     if use_value_centric_cache:
         cache = caches.ValueCentricRamCache(self, kind, max_size=max_size)
     else:
         cache = caches.RamCache(self, kind, max_size=max_size)
     self.cache_registry[kind].append(cache)
     return cache
Esempio n. 3
0
 def testProcessInvalidateRows_All(self):
     ram_cache = caches.RamCache(self.cache_manager, 'issue')
     ram_cache.CacheAll({
         33: 'issue 33',
         34: 'issue 34',
     })
     rows = [(991, 'issue', 34), (992, 'project', 789),
             (993, 'issue', cachemanager_svc.INVALIDATE_ALL_KEYS)]
     self.cache_manager._ProcessInvalidationRows(rows)
     self.assertEqual(993, self.cache_manager.processed_invalidations_up_to)
     self.assertEqual({}, ram_cache.cache)
Esempio n. 4
0
 def testProcessInvalidateRows_Some(self):
     ram_cache = caches.RamCache(self.cache_manager, 'issue')
     ram_cache.CacheAll({
         33: 'issue 33',
         34: 'issue 34',
     })
     rows = [(1, 'issue', 34), (2, 'project', 789), (3, 'issue', 39)]
     self.cache_manager._ProcessInvalidationRows(rows)
     self.assertEqual(3, self.cache_manager.processed_invalidations_up_to)
     self.assertTrue(ram_cache.HasItem(33))
     self.assertFalse(ram_cache.HasItem(34))
Esempio n. 5
0
 def testDoDistributedInvalidation_Some(self):
     ram_cache = caches.RamCache(self.cache_manager, 'issue')
     ram_cache.CacheAll({
         33: 'issue 33',
         34: 'issue 34',
     })
     rows = [(1, 'issue', 34), (2, 'project', 789), (3, 'issue', 39)]
     self.SetUpDoDistributedInvalidation(rows)
     self.mox.ReplayAll()
     self.cache_manager.DoDistributedInvalidation(self.cnxn)
     self.mox.VerifyAll()
     self.assertEqual(3, self.cache_manager.processed_invalidations_up_to)
     self.assertTrue(ram_cache.HasItem(33))
     self.assertFalse(ram_cache.HasItem(34))
Esempio n. 6
0
  def __init__(self, cache_manager):
    """Initialize this module so that it is ready to use.

    Args:
      cache_manager: local cache with distributed invalidation.
    """
    self.project_tbl = sql.SQLTableManager(PROJECT_TABLE_NAME)
    self.user2project_tbl = sql.SQLTableManager(USER2PROJECT_TABLE_NAME)
    self.extraperm_tbl = sql.SQLTableManager(EXTRAPERM_TABLE_NAME)
    self.membernotes_tbl = sql.SQLTableManager(MEMBERNOTES_TABLE_NAME)
    self.usergroupprojects_tbl = sql.SQLTableManager(
        USERGROUPPROJECTS_TABLE_NAME)
    self.acexclusion_tbl = sql.SQLTableManager(
        AUTOCOMPLETEEXCLUSION_TABLE_NAME)

    # Like a dictionary {project_id: project}
    self.project_2lc = ProjectTwoLevelCache(cache_manager, self)

    # The project name to ID cache can never be invalidated by individual
    # project changes because it is keyed by strings instead of ints.  In
    # the case of rare operations like deleting a project (or a future
    # project renaming feature), we just InvalidateAll().
    self.project_names_to_ids = caches.RamCache(cache_manager, 'project')
Esempio n. 7
0
 def _MakeCache(self, cache_manager, kind, max_size=None):
   """Make the RAM cache and register it with the cache_manager."""
   return caches.RamCache(cache_manager, kind, max_size=max_size)
Esempio n. 8
0
def InitializeArtValues(services):
  global art_values_cache
  art_values_cache = caches.RamCache(
      services.cache_manager, 'issue', max_size=settings.issue_cache_max_size)
Esempio n. 9
0
 def setUp(self):
   self.cnxn = 'fake connection'
   self.cache_manager = fake.CacheManager()
   self.ram_cache = caches.RamCache(self.cache_manager, 'issue', max_size=3)