<commit_before>/**
 * Copyright (C) <NAME>
 *
 * 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 no.digipost.api.client.internal;

import no.digipost.api.client.SenderId;
import no.digipost.api.client.representations.EntryPoint;
import no.digipost.api.client.representations.sender.SenderInformation;
import no.digipost.cache2.inmemory.Cache;
import no.digipost.cache2.inmemory.SingleCached;

import java.time.Duration;
import java.util.concurrent.Callable;

import static no.digipost.cache2.inmemory.CacheConfig.expireAfterAccess;
import static no.digipost.cache2.inmemory.CacheConfig.useSoftValues;

final class Cached {

    final SingleCached<EntryPoint> entryPoint;
    final Cache<SenderId, EntryPoint> senderEntryPoint;
    final Cache<String, SenderInformation> senderInformation;

    Cached(Callable<EntryPoint> entryPointFetcher) {
        this.entryPoint = new SingleCached<>("digipost-entrypoint", entryPointFetcher, expireAfterAccess(Duration.ofMinutes(5)), useSoftValues);
        this.senderInformation = Cache.create("sender-information", expireAfterAccess(Duration.ofMinutes(5)), useSoftValues);
        this.senderEntryPoint = Cache.create("digipost-sender-information", expireAfterAccess(Duration.ofMinutes(5)), useSoftValues);
    }

}<commit_msg>Fixes so that cachees that is used a lot will invalidate after 1 hour regardless of use. We see that clients using frequent requests never expires the cache and that can cause problems if the cache is in a never expire state.<commit_after>/**
 * Copyright (C) <NAME> AS
 *
 * 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 no.digipost.api.client.internal;

import no.digipost.api.client.SenderId;
import no.digipost.api.client.representations.EntryPoint;
import no.digipost.api.client.representations.sender.SenderInformation;
import no.digipost.cache2.inmemory.Cache;
import no.digipost.cache2.inmemory.SingleCached;

import java.time.Duration;
import java.util.concurrent.Callable;

import static no.digipost.cache2.inmemory.CacheConfig.expireAfterAccess;
import static no.digipost.cache2.inmemory.CacheConfig.expireAfterWrite;
import static no.digipost.cache2.inmemory.CacheConfig.useSoftValues;

final class Cached {

    final SingleCached<EntryPoint> entryPoint;
    final Cache<SenderId, EntryPoint> senderEntryPoint;
    final Cache<String, SenderInformation> senderInformation;

    Cached(Callable<EntryPoint> entryPointFetcher) {
        this.entryPoint = new SingleCached<>("digipost-entrypoint", entryPointFetcher, expireAfterAccess(Duration.ofMinutes(5)), expireAfterWrite(Duration.ofHours(1)), useSoftValues);
        this.senderInformation = Cache.create("sender-information", expireAfterAccess(Duration.ofMinutes(5)), expireAfterWrite(Duration.ofHours(1)), useSoftValues);
        this.senderEntryPoint = Cache.create("digipost-sender-information", expireAfterAccess(Duration.ofMinutes(5)), expireAfterWrite(Duration.ofHours(1)), useSoftValues);
    }

}
{'fraction_non_alphanumeric': 0.09246231155778895, 'fraction_numerical': 0.0067839195979899495, 'mean_word_length': 5.1340523882896765, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5104667', 'n_tokens_mistral': 1126, 'n_tokens_neox': 1106, 'n_words': 316}