prismicio-community / java-kit

Community maintained development kit for Prismic and the Java language
https://prismic.io
15 stars 38 forks source link

No way of setting a custom cache when using io.prismic.servlet.PrismicFilter #70

Open meyertee opened 6 years ago

meyertee commented 6 years ago

The Api is always initialized this way in PrismicFilter: Api.get(endpoint, accessToken, referenceFromCookies), which will always use Cache.DefaultCache.getInstance() so there is no way of setting a custom cache instance.

Adding a bean as demonstrated in the java-springmvc-starter-project has no effect.

I guess it's difficult to do when using the PrismicFilter with XML configuration, but it would be easy when using Java-based configuration, e.g.:

    @Bean
    public Cache prismicCache() {
        return new BuiltInCache(200);
    }

    @Bean
    public FilterRegistrationBean prismicFilter(@Value("${prismic.endpoint}") String endpoint, @Value("${prismic.accessToken}") String accessToken, Cache cache) {
        FilterRegistrationBean registrationBean = new FilterRegistrationBean();
        Filter filter = new PrismicFilter();
        // this could be: Filter filter = new PrismicFilter(cache);
        registrationBean.addInitParameter("endpoint", endpoint);
        registrationBean.addInitParameter("accessToken", accessToken);
        registrationBean.setFilter(filter);
        registrationBean.setUrlPatterns(Collections.singleton("/*"));
        return registrationBean;
    }

It's easy to work around this and avoid using the built in PrismicFilter, but it would be handy if it were possible. At the least some documentation would be helpful I guess.