This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
java -jar target/spring-caching-1.0-SNAPSHOT.jar --spring.profiles.active=ehcache |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
localhost:~ zoltan$ curl localhost:8080/lookup?name=backbase | |
{"name":"Backbase","website":"http://www.backbase.com/","lookupTime":90}localhost:~ zoltan$ curl localhost:8080/lookup?name=backbase | |
{"name":"Backbase","website":"http://www.backbase.com/","lookupTime":62}localhost:~ zoltan$ curl localhost:8080/lookup?name=backbase | |
{"name":"Backbase","website":"http://www.backbase.com/","lookupTime":65}localhost:~ zoltan$ curl localhost:8080/lookup?name=backbase | |
{"name":"Backbase","website":"http://www.backbase.com/","lookupTime":70}localhost:~ zoltan$ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mvn clean install | |
java -jar target/spring-caching-1.0-SNAPSHOT.jar |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RequestMapping(method = RequestMethod.GET) | |
public @ResponseBody Page lookup(@RequestParam String name) { | |
long start = System.currentTimeMillis(); | |
Page page = facebook.findPage(name); | |
long elapsed = System.currentTimeMillis() - start; | |
page.setLookupTime(elapsed); | |
return page; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Configuration | |
@EnableCaching | |
@Profile("redis") | |
public class RedisConfiguration { | |
@Bean | |
JedisConnectionFactory connectionFactory() { | |
return new JedisConnectionFactory(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Configuration | |
@EnableCaching | |
@Profile("hazelcast") | |
public class HazelcastConfiguration { | |
@Bean | |
HazelcastCacheManager hazelcastcacheManager() throws Exception { | |
return new HazelcastCacheManager(hazelcastInstance()); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Configuration | |
@EnableCaching | |
@Profile("ehcache") | |
public class EhCacheConfiguration { | |
@Bean | |
EhCacheCacheManager ehCacheCacheManager() { | |
return new EhCacheCacheManager(ehCacheManagerFactoryBean().getObject()); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Service | |
public class FacebookLookupService { | |
private static final Logger LOGGER = LoggerFactory.getLogger(FacebookLookupService.class); | |
private RestTemplate restTemplate; | |
@Autowired | |
public FacebookLookupService(RestTemplate restTemplate) { | |
this.restTemplate = restTemplate; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class UserDetailsServiceAdapter implements UserDetailsService { | |
@Autowired | |
private AccountRepository accountRepository; | |
@Override | |
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { | |
Account account = accountRepository.findByEmail(username); | |
if (account == null) { | |
throw new UsernameNotFoundException(username); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
protected void configure(HttpSecurity http) throws Exception { | |
http.authorizeRequests() | |
.antMatchers("/signup", "/static/**").permitAll() | |
.antMatchers("/code").hasRole("PRE_AUTH_USER") | |
.antMatchers("/home").hasRole("USER") | |
.anyRequest().authenticated(); | |
http.formLogin() | |
.loginPage("/login") |