Search in sources :

Example 1 with Cache

use of com.google.gerrit.server.cache.proto.Cache in project gerrit by GerritCodeReview.

the class ProjectCacheImpl method module.

public static Module module() {
    return new CacheModule() {

        @Override
        protected void configure() {
            // We split the project cache into two parts for performance reasons:
            // 1) An in-memory part that has only the project name as key.
            // 2) A persisted part that has the name and revision as key.
            // 
            // When loading dashboards or returning change query results we potentially
            // need to access hundreds of projects because each change could originate in
            // a different project and, through inheritance, require us to check even more
            // projects when evaluating permissions. It's not feasible to read the revision
            // of refs/meta/config from each of these repos as that would require opening
            // them all and reading their ref list or table.
            // At the same time, we want the persisted cache to be immutable and we want it
            // to be impossible that a value for a given key is out of date. We therefore
            // require a revision in the key. That is in line with the rest of the caches in
            // Gerrit.
            // 
            // Splitting the cache into two chunks internally in this class allows us to retain
            // the existing performance guarantees of not requiring reads for the repo for values
            // cached in-memory but also to persist the cache which leads to a much improved
            // cold-start behavior and in-memory miss latency.
            cache(CACHE_NAME, Project.NameKey.class, CachedProjectConfig.class).loader(InMemoryLoader.class).refreshAfterWrite(Duration.ofMinutes(15)).expireAfterWrite(Duration.ofHours(1));
            persist(PERSISTED_CACHE_NAME, Cache.ProjectCacheKeyProto.class, CachedProjectConfig.class).loader(PersistedLoader.class).keySerializer(new ProtobufSerializer<>(Cache.ProjectCacheKeyProto.parser())).valueSerializer(PersistedProjectConfigSerializer.INSTANCE).diskLimit(// 1 GiB
            1 << 30).version(4).maximumWeight(0);
            cache(CACHE_LIST, ListKey.class, new TypeLiteral<ImmutableSortedSet<Project.NameKey>>() {
            }).maximumWeight(1).loader(Lister.class);
            bind(ProjectCacheImpl.class);
            bind(ProjectCache.class).to(ProjectCacheImpl.class);
            install(new LifecycleModule() {

                @Override
                protected void configure() {
                    listener().to(ProjectCacheWarmer.class);
                }
            });
        }
    };
}
Also used : CachedProjectConfig(com.google.gerrit.entities.CachedProjectConfig) CacheModule(com.google.gerrit.server.cache.CacheModule) Project(com.google.gerrit.entities.Project) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) LoadingCache(com.google.common.cache.LoadingCache) Cache(com.google.gerrit.server.cache.proto.Cache) LifecycleModule(com.google.gerrit.lifecycle.LifecycleModule)

Aggregations

LoadingCache (com.google.common.cache.LoadingCache)1 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)1 CachedProjectConfig (com.google.gerrit.entities.CachedProjectConfig)1 Project (com.google.gerrit.entities.Project)1 LifecycleModule (com.google.gerrit.lifecycle.LifecycleModule)1 CacheModule (com.google.gerrit.server.cache.CacheModule)1 Cache (com.google.gerrit.server.cache.proto.Cache)1