spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories

Spring Cache not working in doFilter


How about extending org.springframework.web.filter.GenericFilterBean, and moving the caching details into a separate service class

CacheService

import java.util.Arrays;

import org.springframework.cache.CacheManager;
import
org.springframework.cache.annotation.Cacheable;
import
org.springframework.cache.concurrent.ConcurrentMapCache;
import
org.springframework.cache.support.SimpleCacheManager;
import
org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

    @Component
    public class CacheService{

        @Bean
        public CacheManager cacheManager() {
            SimpleCacheManager cacheManager = new
SimpleCacheManager();
            cacheManager.setCaches(Arrays.asList(
                    new
ConcurrentMapCache("tenants")               
                ));
            return cacheManager;
        }


        @Cacheable("tenants")
        public void display(int number) {
            // if cache working properly, code
below will not execute after the first calling
            for(int i=0; i<50; i++) {   
                   System.out.println("ramon
called" +number);
            }
        }
    }

CredentialsInjectionFilter

import java.io.IOException;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import
org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.web.filter.GenericFilterBean;

@Component
public class CredentialsInjectionFilter extends
GenericFilterBean {

    @Autowired
    private CacheService cacheService;

    @Override
    public void doFilter(ServletRequest
servletRequest, ServletResponse servletResponse,
FilterChain filterChain)
    throws IOException, ServletException {
        cacheService.display(5);
        filterChain.doFilter(servletRequest,
servletResponse);
    }
}

Categories : Java

Related to : Spring Cache not working in doFilter
Spring Security UserDetails cache
EhCacheBasedUserCache uses, as the name implies, the widely used Ehcache library for actual caching. SpringCacheBasedUserCache uses Spring's own caching abstraction. With this you can for example plugin JCache, a.k.a. JSR-107. The reason you find fewer examples of this is that it is newer, the JSR-107 did not reach a Final Release until 18 Mar, 2014. Note that JSR-107 is an API, not an actual imp

Categories : Java
MongoDB Spring Data Repository - Cache methods
From the Spring documentation on caches: Spring recommends that you only annotate concrete classes (and methods of concrete classes) with the @Cache* annotation, as opposed to annotating interfaces. You certainly can place the @Cache* annotation on an interface (or an interface method), but this works only as you would expect it to if you are using interface-based proxies. The fact t

Categories : Java
Memory cache is not working properly
Let me answer it myself... Code in Uboot is a little misleading... it run set_section_dcache(i, DCACHE_WRITEBACK_WRITETHROUGH) but after checking the MMU, it turns out that the memory type is set to be device.

Categories : Caching
Want a cache filter attribute that keep data in cache till user logged in
HttpResponse.RemoveOutputCacheItem should work unless you are using querystring or additional route parameters. You can always use VaryByCustomto make sure cache holds only for a duration of a session but you have to make sure you clear the session once user is logged out. Global.asax.cs: public class MvcApplication : HttpApplication { ... public override string GetVaryByCustomString(HttpC

Categories : C#
Chrome clear cache extension - when run cache is not cleared immediately
The chrome.browsingData.removeCache method is asynchronous (i.e. non-blocking). This means that if you immediately reload the tab after calling removeCache, the removeCache call is still being processed and the cache may not be empty yet. To get the desired behavior, wait until the cache is cleared, by putting the reload call in the callback to removeCache. And by the way, you don't need to call

Categories : Javascript
Recently Add
Redirecting the output directory of 'mvn package' or 'mvn compile' command
No suitable constructor found for ProductoExtranjero
java Composite design pattern(Directory &File)
Java JTree's ui refresh after removing node from parent
First REST Spring application
How to cancel Indexing of a Solr document using Update Request Processor
PowerMock - Mock a Singleton with a Private Constructor
Calling a Postgres stored function SQL error
Where to store Morphlines Java custom command class?
Generic repository using map
How can I scroll a ScrolledComposited in Eclipse SWT Design view?
2 Frames/layout in 1 Activity
Writing a switch differently
Next button opens another activity when its reaches the array limit
Is EclipseLink MOXy capable of applying JSR-303 Bean Validation when unmarshalling XML to object?
Why my jdk can't work,and before the java_home, there is a space that is not from me
How to add List of objects in a Map
How to make notepad++ function like regular notepad in cmd?
Cell renderer and the lost focus
how can I implement iterable for LinkedList>
Disable Androids image-crunch in eclipse (run as) builds
java 8 lambda myMap.stream().count() != myMap.size() after merging myMap
Issue with Calendar calculation that spans 2 calendar years
JSF 2.0 Spring bean injection
Java Regex ReplaceAll with grouping
Getting any word and last word using sed
Clicking on link on JEditorPane throws IOException
printing out difference of two arrays
Spring Bean Alias in JavaConfig
Using Factory Method to Create Generics
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.