Skip to content

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

@meyertee

Description

@meyertee

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions