LCOV - code coverage report
Current view: top level - server/account/externalids - ExternalIdCacheModule.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 11 11 100.0 %
Date: 2022-11-19 15:00:39 Functions: 3 3 100.0 %

          Line data    Source code
       1             : // Copyright (C) 2017 The Android Open Source Project
       2             : //
       3             : // Licensed under the Apache License, Version 2.0 (the "License");
       4             : // you may not use this file except in compliance with the License.
       5             : // You may obtain a copy of the License at
       6             : //
       7             : // http://www.apache.org/licenses/LICENSE-2.0
       8             : //
       9             : // Unless required by applicable law or agreed to in writing, software
      10             : // distributed under the License is distributed on an "AS IS" BASIS,
      11             : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      12             : // See the License for the specific language governing permissions and
      13             : // limitations under the License.
      14             : 
      15             : package com.google.gerrit.server.account.externalids;
      16             : 
      17             : import com.google.gerrit.server.cache.CacheModule;
      18             : import com.google.gerrit.server.cache.serialize.ObjectIdCacheSerializer;
      19             : import com.google.inject.TypeLiteral;
      20             : import java.time.Duration;
      21             : import org.eclipse.jgit.lib.ObjectId;
      22             : 
      23         152 : public class ExternalIdCacheModule extends CacheModule {
      24             :   @Override
      25             :   protected void configure() {
      26         152 :     persist(ExternalIdCacheImpl.CACHE_NAME, ObjectId.class, new TypeLiteral<AllExternalIds>() {})
      27             :         // The cached data is potentially pretty large and we are always only interested
      28             :         // in the latest value. However, due to a race condition, it is possible for different
      29             :         // threads to observe different values of the meta ref, and hence request different keys
      30             :         // from the cache. Extend the cache size by 1 to cover this case, but expire the extra
      31             :         // object after a short period of time, since it may be a potentially large amount of
      32             :         // memory.
      33             :         // When loading a new value because the primary data advanced, we want to leverage the old
      34             :         // cache state to recompute only what changed. This doesn't affect cache size though as
      35             :         // Guava calls the loader first and evicts later on.
      36         152 :         .maximumWeight(2)
      37         152 :         .expireFromMemoryAfterAccess(Duration.ofMinutes(1))
      38         152 :         .diskLimit(-1)
      39         152 :         .version(1)
      40         152 :         .keySerializer(ObjectIdCacheSerializer.INSTANCE)
      41         152 :         .valueSerializer(AllExternalIds.Serializer.INSTANCE);
      42             : 
      43         152 :     bind(ExternalIdCacheImpl.class);
      44         152 :     bind(ExternalIdCache.class).to(ExternalIdCacheImpl.class);
      45         152 :   }
      46             : }

Generated by: LCOV version 1.16+git.20220603.dfeb750