All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mitchellbosecke.pebble.cache.template.CaffeineTemplateCache Maven / Gradle / Ivy

There is a newer version: 3.2.2
Show newest version
package com.mitchellbosecke.pebble.cache.template;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.mitchellbosecke.pebble.cache.PebbleCache;
import com.mitchellbosecke.pebble.template.PebbleTemplate;
import java.util.function.Function;

public class CaffeineTemplateCache implements PebbleCache {

  private final Cache templateCache;

  public CaffeineTemplateCache() {
    this.templateCache = Caffeine.newBuilder()
        .maximumSize(200)
        .build();
  }

  public CaffeineTemplateCache(Cache templateCache) {
    this.templateCache = templateCache;
  }

  @Override
  public PebbleTemplate computeIfAbsent(Object key,
      Function mappingFunction) {
    return this.templateCache.get(key, mappingFunction);
  }

  @Override
  public void invalidateAll() {
    this.templateCache.invalidateAll();
  }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy