@Test(expected = IllegalArgumentException.class) public void testCacheDoesNotTolerateNullResourceWrite() throws Exception { request(() -> { testee.put(null, key(), this.model); putModelInCache(); }); }
public <T> void put(@Nonnull Resource resource, @Nonnull Key key, @CheckForNull T model) { if (resource == null) { throw new IllegalArgumentException("Method argument resource must not be null."); } if (key == null) { throw new IllegalArgumentException("Method argument key must not be null."); } if (!this.configuration.enabled()) { return; } Map<Key, Optional<?>> cache = this.cacheHolder.get(); if (cache == null) { this.logger.debug("No cache found, the cache will not be used."); return; } final Optional<?> storedValue = ofNullable(model); if (this.configuration.safeMode()) { cache.put(createSafeModeKey(resource, key), storedValue); return; } cache.put(createKey(resource, key), storedValue); }
RequestScopedResourceModelCache implements Filter { public <T> void put(@Nonnull Resource resource, @Nonnull Key key, @CheckForNull T model) { if (resource == null) { throw new IllegalArgumentException("Method argument resource must not be null."); } if (key == null) { throw new IllegalArgumentException("Method argument key must not be null."); } if (!this.configuration.enabled()) { return; } Map<Key, Optional<?>> cache = this.cacheHolder.get(); if (cache == null) { this.logger.debug("No cache found, the cache will not be used."); return; } final Optional<?> storedValue = ofNullable(model); if (this.configuration.safeMode()) { cache.put(createSafeModeKey(resource, key), storedValue); return; } cache.put(createKey(resource, key), storedValue); } }
RequestScopedResourceModelCache implements Filter { public <T> void put(@Nonnull Resource resource, @Nonnull Key key, @CheckForNull T model) { if (resource == null) { throw new IllegalArgumentException("Method argument resource must not be null."); } if (key == null) { throw new IllegalArgumentException("Method argument key must not be null."); } if (!this.configuration.enabled()) { return; } Map<Key, Optional<?>> cache = this.cacheHolder.get(); if (cache == null) { this.logger.debug("No cache found, the cache will not be used."); return; } final Optional<?> storedValue = ofNullable(model); if (this.configuration.safeMode()) { cache.put(createSafeModeKey(resource, key), storedValue); return; } cache.put(createKey(resource, key), storedValue); }  }
RequestScopedResourceModelCache implements Filter { public <T> void put(@Nonnull Resource resource, @Nonnull Key key, @CheckForNull T model) { if (resource == null) { throw new IllegalArgumentException("Method argument resource must not be null."); } if (key == null) { throw new IllegalArgumentException("Method argument key must not be null."); } if (!this.configuration.enabled()) { return; } Map<Key, Optional<?>> cache = this.cacheHolder.get(); if (cache == null) { this.logger.debug("No cache found, the cache will not be used."); return; } final Optional<?> storedValue = ofNullable(model); if (this.configuration.safeMode()) { cache.put(createSafeModeKey(resource, key), storedValue); return; } cache.put(createKey(resource, key), storedValue); }  @CheckForNull @SuppressWarnings("unchecked") Optional<T> get(@Nonnull Resource resource, @Nonnull Key key); void put(@Nonnull Resource resource, @Nonnull Key key, @CheckForNull T model); @Override void doFilter(@Nonnull ServletRequest request, @Nonnull ServletResponse response, @Nonnull FilterChain chain); @Override void init(FilterConfig filterConfig); @Override void destroy(); }
RequestScopedResourceModelCache implements Filter { public <T> void put(@Nonnull Resource resource, @Nonnull Key key, @CheckForNull T model) { if (resource == null) { throw new IllegalArgumentException("Method argument resource must not be null."); } if (key == null) { throw new IllegalArgumentException("Method argument key must not be null."); } if (!this.configuration.enabled()) { return; } Map<Key, Optional<?>> cache = this.cacheHolder.get(); if (cache == null) { this.logger.debug("No cache found, the cache will not be used."); return; } final Optional<?> storedValue = ofNullable(model); if (this.configuration.safeMode()) { cache.put(createSafeModeKey(resource, key), storedValue); return; } cache.put(createKey(resource, key), storedValue); }  @CheckForNull @SuppressWarnings("unchecked") Optional<T> get(@Nonnull Resource resource, @Nonnull Key key); void put(@Nonnull Resource resource, @Nonnull Key key, @CheckForNull T model); @Override void doFilter(@Nonnull ServletRequest request, @Nonnull ServletResponse response, @Nonnull FilterChain chain); @Override void init(FilterConfig filterConfig); @Override void destroy();  }