Files
gerrit/java/com/google/gerrit/server/CacheRefreshExecutor.java
Patrick Hiesel d70f37fc45 Replace ProjectCacheClock with refreshAfterWrite
This commit replaces a home-grown piece of infrastructure with
a standard component that has the same behavior.

ProjectCacheClock was used to detect values in ProjectCache that
are old enough that they might be out of date. It would then
schedule a task on a background thread to check the value.

Both Guava Caches and Caffeine Caches offer this as standard
functionality: refreshAfterWrite.

This is even better than what we had with ProjectCacheClock
because it does the actual refreshing (= reloading the value)
on the background thread.

In a prior commit, we have implemented this option in our own
Cache config framework and the H2 persistent store.

This commit makes use of that prework in the ProjectCache. We
set the default refreshAfterWrite to 15 minutes and the
expireAfterWrite - the duration after which a value is not
read anymore - to 1 hour. Both are configurable. It is also
possible to disable this behavior entirely.

Similar to ProjectCacheClock, we use a dedicated executor for
refreshing cached values. The executor is generic and not
specific to ProjectCache. It's size is configurable.

Change-Id: I8b163853ae092444edf9ff44bef4f7910f21ba0e
2020-05-27 08:51:37 +02:00

29 lines
996 B
Java

// Copyright (C) 2020 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.server;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import com.google.inject.BindingAnnotation;
import java.lang.annotation.Retention;
/**
* Marker on the global {@link java.util.concurrent.ThreadPoolExecutor} used to refresh outdated
* values in caches.
*/
@Retention(RUNTIME)
@BindingAnnotation
public @interface CacheRefreshExecutor {}