This file contains 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; | |
} | |
@Cacheable("pages") | |
public Page findPage(String page) { | |
LOGGER.info("calling findPage with {}", page); | |
return restTemplate.getForObject("http://graph.facebook.com/" + page, Page.class); | |
} | |
} |
In this simple example the service is exposed via a Spring MVC controller as seen below, where we also measure how long it takes to call the service method.
This file contains 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 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 |
Now, in another terminal let's call the service couple of times with the same name.
This file contains 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 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()); | |
} | |
@Bean | |
EhCacheManagerFactoryBean ehCacheManagerFactoryBean() { | |
EhCacheManagerFactoryBean ehCacheManagerFactoryBean = new EhCacheManagerFactoryBean(); | |
ehCacheManagerFactoryBean.setConfigLocation(new ClassPathResource("ehcache.xml")); | |
return ehCacheManagerFactoryBean; | |
} | |
} |
This file contains 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 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":572}localhost:~ zoltan$ curl localhost:8080/lookup?nam=backbase | |
{"name":"Backbase","website":"http://www.backbase.com/","lookupTime":1}localhost:~ zoltan$ curl localhost:8080/lookup?name=backbase | |
{"name":"Backbase","website":"http://www.backbase.com/","lookupTime":0}localhost:~ zoltan$ curl localhost:8080/lookup?name=backbase | |
{"name":"Backbase","website":"http://www.backbase.com/","lookupTime":1}localhost:~ zoltan$ curl localhost:8080/lookup?name=backbase | |
{"name":"Backbase","website":"http://www.backbase.com/","lookupTime":0}localhost:~ zoltan$ |
This file contains 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()); | |
} | |
@Bean | |
HazelcastInstance hazelcastInstance() throws Exception { | |
return Hazelcast.newHazelcastInstance(); | |
} | |
} |
This file contains 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=hazelcast --server.port=8081 | |
java -jar target/spring-caching-1.0-SNAPSHOT.jar --spring.profiles.active=hazelcast --server.port=8082 |
This file contains 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:8082/lookup?name=google | |
{"name":"Google","website":"www.google.com","lookupTime":132}localhost:~ zoltan$ curl localhost:8081/lookup?name=google | |
{"name":"Google","website":"www.google.com","lookupTime":3}localhost:~ zoltan$ |
20 comments:
Very useful article.
Is it possible to have all the 3 fields (username, password, verification code) in single page ? If all 3 combinations are correct then set the Authorities on SecurityContext else throw exceptions. I am able to implement till user / password combination. But I want to put a small piece of java code for the OTP (2factor authentication). But not sure where to put this piece of Java code. Should I use filters ?
Thanks
Jay
Informative article indeed,
Spring cache abstraction has enabled to separate application's business logic from caching. Thus enabling programmer to improve applications performance along with the ease of switching caching solution to the optimum one.
However a generic solution for caching abstraction has limited caching features provided by caching vendors.
E.g. TayzGrid, a distributed caching solution by Alachisoft also provides spring caching solution. But its feature set has been limited in spring caching. However along with multiple caching topologies, it provides other caching features for spring through configuration files.
-Sameer Shah
I got lot of ideas after reading this. Share more as similar to this. Thank you for shared this.
C C++ Training in Chennai
c c++ classes
C C++ Training in OMR
C C++ Training in Adyar
JMeter Training in Chennai
Appium Training in Chennai
javascript training in chennai
core java training in chennai
Great collection and thanks for sharing this info with us. Waiting for more like this.
Data Science Training Institute in Chennai
Data Science Classes in Chennai
Data Science course in Chennai
R Programming Training in Chennai
Data Analytics Training in Chennai
Machine Learning course in Chennai
Machine Learning Training in Velachery
Data Science course in Anna Nagar
Excellent blog!!!Thanks for sharing. Keep doing more.
Spoken English Classes in Chennai
Best Spoken English Classes in Chennai
IELTS Coaching in Chennai
IELTS Coaching Centre in Chennai
English Speaking Classes in Mumbai
English Speaking Course in Mumbai
IELTS Classes in Mumbai
IELTS Coaching in Mumbai
This is an amazing blog, thank you so much for sharing such valuable information with us.
Visit for best website design and SEO services at- Website Development Company in India
best website design services in gurgaon
best web design company in gurgaon
best website design in gurgaon
website design services in gurgaon
website design service in gurgaon
best website designing company in gurgaon
website designing services in gurgaon
web design company in gurgaon
best website designing company in india
top website designing company in india
best web design company in gurgaon
best web designing services in gurgaon
best web design services in gurgaon
website designing in gurgaon
website designing company in gurgaon
website design in gurgaon
graphic designing company in gurgaon
website company in gurgaon
website design company in gurgaon
web design services in gurgaon
best website design company in gurgaon
website company in gurgaon
Website design Company in gurgaon
best website designing services in gurgaon
best web design in gurgaon
website designing company in gurgaon
website development company in gurgaon
web development company in gurgaon
website design company
website designing services
Thanks for sharing an informative blog keep rocking bring more details....each type of qualification, type of Sarkari Job, such as central govt jobs, state govt jobs, district-level sarkari jobs and even contract govt jobs are available, for which aspirants can stay informed...
this is really nice to read..informative post is very good to read..thanks a lot good luck guys.
Ai & Artificial Intelligence Course in Chennai
PHP Training in Chennai
Ethical Hacking Course in Chennai Blue Prism Training in Chennai
UiPath Training in Chennai
I really enjoyed a lot by reading your post thank you so much for providing this information.
AngularJS training in chennai | AngularJS training in anna nagar | AngularJS training in omr | AngularJS training in porur | AngularJS training in tambaram | AngularJS training in velachery
It's really good. Thank you for your information. Keep Blogging!.
Spring training in bangalore
Spring trainers in bangalore
Such a awesome article, I have never seen till now. Thanks for sharing this article. I wish you post some more articles quickly. Thanks alot!
AI Patasala-Artificial Intelligence Course in Hyderabad
AI Patasala-Best Data Science course in Hyderabad
AI Patasala-Best Machine Learning course in Hyderabad
I wanted to thank you for this great read!! I definitely enjoying every little bit of it I have you bookmarked to check out new stuff you post.
data scientist training and placement
This is a smart blog. I mean it. You have so much knowledge about this issue, and so much passion. You also know how to make people rally behind it, obviously from the responses.
data analytics courses in hyderabad with placements
Amazingly by and large very interesting post. I was looking for such an information and thoroughly enjoyed examining this one. Keep posting. An obligation of appreciation is all together for sharing.
data science course in gwalior
Really nice information and informative content. I bookmarked your site for further blogs.
Online Data Science Course in Hyderabad
Therefore dissertation web-sites as a result of online to set-up safe and sound ostensibly taped in the website.
Engineering Jobs | bcom 1st year result 2021 name wise
Very secure message. I basically staggered concerning your blog and wanted to broadcast that i've in all actuality cherished concentrating on your blog entries. Any gaudiness i'll buy in on your feed and I slant you plug again rapidly. tremendous gratitude for the valuable information. Spyhunter 5 Crack
Love failure quotes are for the one who failed in love. Love failure makes you realize the best moments you have lived or are living with Love Failure Quotes
Excellent Article!!! I like the helpful information you provide in your article.davv ba 3rd year result name wise
It had me eager to get into the text.
Edraw Max Patch
Post a Comment