Pivotal: Bootiful Couchbase: microservices with Spring – Couchbase Connect 2016
[Codemash] Caching Made "Bootiful"!
Click here to load reader
-
Upload
viktor-gamov -
Category
Technology
-
view
615 -
download
4
Transcript of [Codemash] Caching Made "Bootiful"!
![Page 1: [Codemash] Caching Made "Bootiful"!](https://reader038.fdocuments.us/reader038/viewer/2022100807/589a9b6b1a28abfc1a8b4741/html5/thumbnails/1.jpg)
![Page 2: [Codemash] Caching Made "Bootiful"!](https://reader038.fdocuments.us/reader038/viewer/2022100807/589a9b6b1a28abfc1a8b4741/html5/thumbnails/2.jpg)
whoiam
Señor Solutions Architect @Hazelcast@gAmUssA on the internetz
![Page 3: [Codemash] Caching Made "Bootiful"!](https://reader038.fdocuments.us/reader038/viewer/2022100807/589a9b6b1a28abfc1a8b4741/html5/thumbnails/3.jpg)
• Performance
• Offload expensive parts of your architecture
• Scale up – get the most out of one machine
• Scale out – add more capacity with more machines
• Usually very fast and easy to apply
Cache is good for…
![Page 4: [Codemash] Caching Made "Bootiful"!](https://reader038.fdocuments.us/reader038/viewer/2022100807/589a9b6b1a28abfc1a8b4741/html5/thumbnails/4.jpg)
![Page 5: [Codemash] Caching Made "Bootiful"!](https://reader038.fdocuments.us/reader038/viewer/2022100807/589a9b6b1a28abfc1a8b4741/html5/thumbnails/5.jpg)
Let’s recap!
![Page 6: [Codemash] Caching Made "Bootiful"!](https://reader038.fdocuments.us/reader038/viewer/2022100807/589a9b6b1a28abfc1a8b4741/html5/thumbnails/6.jpg)
© 2017 Hazelcast Inc. @gamussa
0. Inception
public class SpringwebinarApplication {
public static interface CityService {
public String getCity();
}
@Bean
public CityService getService() {
return new CityService() {
@Override public String getCity() {
// slow code goes here!
return result;
}
};
}
}
![Page 7: [Codemash] Caching Made "Bootiful"!](https://reader038.fdocuments.us/reader038/viewer/2022100807/589a9b6b1a28abfc1a8b4741/html5/thumbnails/7.jpg)
© 2017 Hazelcast Inc. @gamussa
1. Enable Caching
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.EnableCaching;
@SpringBootApplication
@EnableCaching
public class SpringwebinarApplication {
public static interface CityService {
@Cacheable("city")
public String getCity();
}
@Bean
public CityService getService() {
return new CityService() {
@Override public String getCity() {
// slow code goes here!
return result;
}
};
}}
![Page 8: [Codemash] Caching Made "Bootiful"!](https://reader038.fdocuments.us/reader038/viewer/2022100807/589a9b6b1a28abfc1a8b4741/html5/thumbnails/8.jpg)
© 2017 Hazelcast Inc. @gamussa
2. Enable Distributed Caching
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.EnableCaching;
@SpringBootApplication
@EnableCaching
public class SpringwebinarApplication {
public static interface CityService {
@Cacheable("city")
public String getCity();
}
@Bean
public CityService getService() {
return new CityService() {
@Override public String getCity() {
// slow code goes here!
return result;
}
};
}
@Bean
public HazelcastInstance getInstance() {
// return Hazelcast.newHazelcastInstance();
return HazelcastClient.newHazelcastClient();
}
}
![Page 9: [Codemash] Caching Made "Bootiful"!](https://reader038.fdocuments.us/reader038/viewer/2022100807/589a9b6b1a28abfc1a8b4741/html5/thumbnails/9.jpg)
© 2017 Hazelcast Inc. @gamussa
3. Embrace the standards – Enable JCache
import javax.cache.annotation.CacheResult;
import org.springframework.cache.annotation.EnableCaching;
@SpringBootApplication
@EnableCaching
public class SpringwebinarApplication {
public static interface CityService {
@CacheResult(cacheName = "city")
public String getCity();
}
@Bean
public CityService getService() {
return new CityService() {
@Override public String getCity() {
// slow code goes here!
return result;
}
};
}}
![Page 10: [Codemash] Caching Made "Bootiful"!](https://reader038.fdocuments.us/reader038/viewer/2022100807/589a9b6b1a28abfc1a8b4741/html5/thumbnails/10.jpg)