Line data Source code
1 : // Copyright (C) 2013 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.query.change; 16 : 17 : import com.google.common.cache.Cache; 18 : import com.google.gerrit.server.cache.CacheModule; 19 : import com.google.gerrit.server.cache.serialize.BooleanCacheSerializer; 20 : import com.google.inject.Inject; 21 : import com.google.inject.Module; 22 : import com.google.inject.Singleton; 23 : import com.google.inject.name.Named; 24 : import java.util.concurrent.Callable; 25 : import java.util.concurrent.ExecutionException; 26 : 27 : @Singleton 28 : public class ConflictsCacheImpl implements ConflictsCache { 29 : public static final String NAME = "conflicts"; 30 : 31 : public static Module module() { 32 152 : return new CacheModule() { 33 : @Override 34 : protected void configure() { 35 152 : persist(NAME, ConflictKey.class, Boolean.class) 36 152 : .version(1) 37 152 : .keySerializer(ConflictKey.Serializer.INSTANCE) 38 152 : .valueSerializer(BooleanCacheSerializer.INSTANCE) 39 152 : .maximumWeight(37400); 40 152 : bind(ConflictsCache.class).to(ConflictsCacheImpl.class); 41 152 : } 42 : }; 43 : } 44 : 45 : private final Cache<ConflictKey, Boolean> conflictsCache; 46 : 47 : @Inject 48 149 : public ConflictsCacheImpl(@Named(NAME) Cache<ConflictKey, Boolean> conflictsCache) { 49 149 : this.conflictsCache = conflictsCache; 50 149 : } 51 : 52 : @Override 53 : public void put(ConflictKey key, boolean value) { 54 0 : conflictsCache.put(key, value); 55 0 : } 56 : 57 : @Override 58 : public Boolean get(ConflictKey key, Callable<? extends Boolean> loader) 59 : throws ExecutionException { 60 4 : return conflictsCache.get(key, loader); 61 : } 62 : }