{"id":33847,"date":"2014-12-03T10:00:18","date_gmt":"2014-12-03T08:00:18","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/?p=33847"},"modified":"2014-12-02T12:32:36","modified_gmt":"2014-12-02T10:32:36","slug":"spring-request-level-memoization","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2014\/12\/spring-request-level-memoization.html","title":{"rendered":"Spring request-level memoization"},"content":{"rendered":"<h2>Introduction<\/h2>\n<p><a href=\"http:\/\/en.wikipedia.org\/wiki\/Memoization\">Memoization<\/a> is a method-level <a href=\"http:\/\/www.javacodegeeks.com\/2014\/03\/caching-best-practices.html\">caching<\/a> technique for speeding-up consecutive invocations.<\/p>\n<p>This post will demonstrate how you can achieve request-level repeatable reads for any data source, using <a href=\"http:\/\/docs.spring.io\/spring-framework\/docs\/current\/spring-framework-reference\/html\/aop.html\">Spring AOP<\/a> only.<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<\/p>\n<h2>Spring Caching<\/h2>\n<p>Spring offers a very useful <a href=\"http:\/\/docs.spring.io\/spring\/docs\/current\/spring-framework-reference\/html\/cache.html\">caching abstracting<\/a>, allowing you do decouple the application logic from the caching implementation details.<\/p>\n<p>Spring Caching uses an application-level scope, so for a request-only memoization we need to take a <a href=\"http:\/\/en.wikipedia.org\/wiki\/Do_it_yourself\">DIY<\/a> approach.<\/p>\n<h2>Request-level Caching<\/h2>\n<p>A request-level cache entry life-cycle is always bound to the current request scope. Such cache is very similar to Hibernate Persistence Context that offers <a href=\"http:\/\/www.javacodegeeks.com\/2014\/10\/hibernate-application-level-repeatable-reads.html\">session-level repeatable reads<\/a>.<\/p>\n<p><a href=\"2014\/01\/05\/a-beginners-guide-to-acid-and-database-transactions\/\">Repeatable reads<\/a> are mandatory for <a href=\"http:\/\/www.javacodegeeks.com\/2014\/09\/preventing-lost-updates-in-long-conversations.html\">preventing lost updates<\/a>, even for NoSQL solutions.<\/p>\n<h2>Step-by-step implementation<\/h2>\n<p>First we are going to define a Memoizing marker annotation:<\/p>\n<pre class=\" brush:java\">@Target(ElementType.METHOD)\r\n@Retention(RetentionPolicy.RUNTIME)\r\npublic @interface Memoize {\r\n}<\/pre>\n<p>This annotation is going to explicitly mark all methods that need to be memoized.<\/p>\n<p>To distinguish different method invocations we are going to encapsulate the method call info into the following object type:<\/p>\n<pre class=\" brush:java\">public class InvocationContext {\r\n\r\n    public static final String TEMPLATE = \"%s.%s(%s)\";\r\n\r\n    private final Class targetClass;\r\n    private final String targetMethod;\r\n    private final Object[] args;\r\n\r\n    public InvocationContext(Class targetClass, String targetMethod, Object[] args) {\r\n        this.targetClass = targetClass;\r\n        this.targetMethod = targetMethod;\r\n        this.args = args;\r\n    }\r\n\r\n    public Class getTargetClass() {\r\n        return targetClass;\r\n    }\r\n\r\n    public String getTargetMethod() {\r\n        return targetMethod;\r\n    }\r\n\r\n    public Object[] getArgs() {\r\n        return args;\r\n    }\r\n\r\n    @Override\r\n    public boolean equals(Object that) {\r\n        return EqualsBuilder.reflectionEquals(this, that);\r\n    }\r\n\r\n    @Override\r\n    public int hashCode() {\r\n        return HashCodeBuilder.reflectionHashCode(this);\r\n    }\r\n\r\n    @Override\r\n    public String toString() {\r\n        return String.format(TEMPLATE, targetClass.getName(), targetMethod, Arrays.toString(args));\r\n    }\r\n}<\/pre>\n<p>Few know about the awesomeness of Spring <a href=\"http:\/\/docs.spring.io\/spring\/docs\/current\/spring-framework-reference\/html\/beans.html#beans-factory-scopes-request\">Request<\/a>\/<a href=\"http:\/\/docs.spring.io\/spring\/docs\/current\/spring-framework-reference\/html\/beans.html#beans-factory-scopes-session\">Session<\/a> bean scopes.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>Because we require a request-level memoization scope, we can simplify our design with a Spring request scope that hides the actual HttpSession resolving logic:<\/p>\n<pre class=\" brush:java\">@Component\r\n@Scope(proxyMode = ScopedProxyMode.TARGET_CLASS, value = \"request\")\r\npublic class RequestScopeCache {\r\n\r\n    public static final Object NONE = new Object();\r\n\r\n    private final Map&lt;InvocationContext, Object&gt; cache = new HashMap&lt;InvocationContext, Object&gt;();\r\n\r\n    public Object get(InvocationContext invocationContext) {\r\n        return cache.containsKey(invocationContext) ? cache.get(invocationContext) : NONE;\r\n    }\r\n\r\n    public void put(InvocationContext methodInvocation, Object result) {\r\n        cache.put(methodInvocation, result);\r\n    }\r\n}<\/pre>\n<p>Since a mere annotation means nothing without a runtime processing engine, we must therefore define a Spring Aspect implementing the actual memoization logic:<\/p>\n<pre class=\" brush:java;wrap-lines:false\">@Aspect\r\npublic class MemoizerAspect {\r\n\r\n    @Autowired\r\n    private RequestScopeCache requestScopeCache;\r\n\r\n    @Around(\"@annotation(com.vladmihalcea.cache.Memoize)\")\r\n    public Object memoize(ProceedingJoinPoint pjp) throws Throwable {\r\n        InvocationContext invocationContext = new InvocationContext(\r\n                pjp.getSignature().getDeclaringType(),\r\n                pjp.getSignature().getName(),\r\n                pjp.getArgs()\r\n        );\r\n        Object result = requestScopeCache.get(invocationContext);\r\n        if (RequestScopeCache.NONE == result) {\r\n            result = pjp.proceed();\r\n            LOGGER.info(\"Memoizing result {}, for method invocation: {}\", result, invocationContext);\r\n            requestScopeCache.put(invocationContext, result);\r\n        } else {\r\n            LOGGER.info(\"Using memoized result: {}, for method invocation: {}\", result, invocationContext);\r\n        }\r\n        return result;\r\n    }\r\n}<\/pre>\n<h2>Testing time<\/h2>\n<p>Let\u2019s put all this to a test. For simplicity sake, we are going to emulate the request-level scope memoization requirements with a Fibonacci number calculator:<\/p>\n<pre class=\" brush:java\">@Component\r\npublic class FibonacciServiceImpl implements FibonacciService {\r\n\r\n    @Autowired\r\n    private ApplicationContext applicationContext;\r\n\r\n    private FibonacciService fibonacciService;\r\n\r\n    @PostConstruct\r\n    private void init() {\r\n        fibonacciService = applicationContext.getBean(FibonacciService.class);\r\n    }\r\n\r\n    @Memoize\r\n    public int compute(int i) {\r\n        LOGGER.info(\"Calculate fibonacci for number {}\", i);\r\n        if (i == 0 || i == 1)\r\n            return i;\r\n        return fibonacciService.compute(i - 2) + fibonacciService.compute(i - 1);\r\n    }\r\n}<\/pre>\n<p>If we are to calculate the 10th Fibonnaci number, we\u2019ll get the following result:<\/p>\n<pre class=\" brush:bash;wrap-lines:false\">Calculate fibonacci for number 10\r\nCalculate fibonacci for number 8\r\nCalculate fibonacci for number 6\r\nCalculate fibonacci for number 4\r\nCalculate fibonacci for number 2\r\nCalculate fibonacci for number 0\r\nMemoizing result 0, for method invocation: com.vladmihalcea.cache.FibonacciService.compute([0])\r\nCalculate fibonacci for number 1\r\nMemoizing result 1, for method invocation: com.vladmihalcea.cache.FibonacciService.compute([1])\r\nMemoizing result 1, for method invocation: com.vladmihalcea.cache.FibonacciService.compute([2])\r\nCalculate fibonacci for number 3\r\nUsing memoized result: 1, for method invocation: com.vladmihalcea.cache.FibonacciService.compute([1])\r\nUsing memoized result: 1, for method invocation: com.vladmihalcea.cache.FibonacciService.compute([2])\r\nMemoizing result 2, for method invocation: com.vladmihalcea.cache.FibonacciService.compute([3])\r\nMemoizing result 3, for method invocation: com.vladmihalcea.cache.FibonacciService.compute([4])\r\nCalculate fibonacci for number 5\r\nUsing memoized result: 2, for method invocation: com.vladmihalcea.cache.FibonacciService.compute([3])\r\nUsing memoized result: 3, for method invocation: com.vladmihalcea.cache.FibonacciService.compute([4])\r\nMemoizing result 5, for method invocation: com.vladmihalcea.cache.FibonacciService.compute([5])\r\nMemoizing result 8, for method invocation: com.vladmihalcea.cache.FibonacciService.compute([6])\r\nCalculate fibonacci for number 7\r\nUsing memoized result: 5, for method invocation: com.vladmihalcea.cache.FibonacciService.compute([5])\r\nUsing memoized result: 8, for method invocation: com.vladmihalcea.cache.FibonacciService.compute([6])\r\nMemoizing result 13, for method invocation: com.vladmihalcea.cache.FibonacciService.compute([7])\r\nMemoizing result 21, for method invocation: com.vladmihalcea.cache.FibonacciService.compute([8])\r\nCalculate fibonacci for number 9\r\nUsing memoized result: 13, for method invocation: com.vladmihalcea.cache.FibonacciService.compute([7])\r\nUsing memoized result: 21, for method invocation: com.vladmihalcea.cache.FibonacciService.compute([8])\r\nMemoizing result 34, for method invocation: com.vladmihalcea.cache.FibonacciService.compute([9])\r\nMemoizing result 55, for method invocation: com.vladmihalcea.cache.FibonacciService.compute([10])<\/pre>\n<h2>Conclusion<\/h2>\n<p>Memoization is a cross-cutting concern and Spring AOP allows you to decouple the caching details from the actual application logic code.<\/p>\n<ul>\n<li>Code available on <a href=\"https:\/\/github.com\/vladmihalcea\/vladmihalcea.wordpress.com\/tree\/master\/misc\">GitHub<\/a>.<\/li>\n<\/ul>\n<div class=\"attribution\">\n<table>\n<tbody>\n<tr>\n<td><span class=\"reference\">Reference: <\/span><\/td>\n<td><a href=\"http:\/\/vladmihalcea.com\/2014\/12\/01\/spring-request-level-memoization\/\">Spring request-level memoization<\/a> from our <a href=\"http:\/\/www.javacodegeeks.com\/jcg\/\">JCG partner<\/a> Vlad Mihalcea at the <a href=\"http:\/\/vladmihalcea.com\/\">Vlad Mihalcea&#8217;s Blog<\/a> blog.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Memoization is a method-level caching technique for speeding-up consecutive invocations. This post will demonstrate how you can achieve request-level repeatable reads for any data source, using Spring AOP only. &nbsp; &nbsp; &nbsp; &nbsp; Spring Caching Spring offers a very useful caching abstracting, allowing you do decouple the application logic from the caching implementation details. &hellip;<\/p>\n","protected":false},"author":507,"featured_media":240,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[30],"class_list":["post-33847","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-spring"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Spring request-level memoization<\/title>\n<meta name=\"description\" content=\"Introduction Memoization is a method-level caching technique for speeding-up consecutive invocations. This post will demonstrate how you can achieve\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2014\/12\/spring-request-level-memoization.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Spring request-level memoization\" \/>\n<meta property=\"og:description\" content=\"Introduction Memoization is a method-level caching technique for speeding-up consecutive invocations. This post will demonstrate how you can achieve\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2014\/12\/spring-request-level-memoization.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/vlad.mihalcea.71\" \/>\n<meta property=\"article:published_time\" content=\"2014-12-03T08:00:18+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Vlad Mihalcea\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Vlad Mihalcea\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/12\\\/spring-request-level-memoization.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/12\\\/spring-request-level-memoization.html\"},\"author\":{\"name\":\"Vlad Mihalcea\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/2c2d5059ee4fd88b1b3b9e52efc5b129\"},\"headline\":\"Spring request-level memoization\",\"datePublished\":\"2014-12-03T08:00:18+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/12\\\/spring-request-level-memoization.html\"},\"wordCount\":306,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/12\\\/spring-request-level-memoization.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"keywords\":[\"Spring\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/12\\\/spring-request-level-memoization.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/12\\\/spring-request-level-memoization.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/12\\\/spring-request-level-memoization.html\",\"name\":\"Spring request-level memoization\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/12\\\/spring-request-level-memoization.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/12\\\/spring-request-level-memoization.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"datePublished\":\"2014-12-03T08:00:18+00:00\",\"description\":\"Introduction Memoization is a method-level caching technique for speeding-up consecutive invocations. This post will demonstrate how you can achieve\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/12\\\/spring-request-level-memoization.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/12\\\/spring-request-level-memoization.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/12\\\/spring-request-level-memoization.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"spring-interview-questions-answers\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2014\\\/12\\\/spring-request-level-memoization.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Spring request-level memoization\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/2c2d5059ee4fd88b1b3b9e52efc5b129\",\"name\":\"Vlad Mihalcea\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/f9f4ac0b2229b9f9fb993393b822ffbf63e60c1665a244176d3c4728565a9a9f?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/f9f4ac0b2229b9f9fb993393b822ffbf63e60c1665a244176d3c4728565a9a9f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/f9f4ac0b2229b9f9fb993393b822ffbf63e60c1665a244176d3c4728565a9a9f?s=96&d=mm&r=g\",\"caption\":\"Vlad Mihalcea\"},\"description\":\"Vlad Mihalcea is a software architect passionate about software integration, high scalability and concurrency challenges.\",\"sameAs\":[\"http:\\\/\\\/vladmihalcea.wordpress.com\\\/\",\"https:\\\/\\\/www.facebook.com\\\/vlad.mihalcea.71\",\"http:\\\/\\\/www.linkedin.com\\\/pub\\\/vlad-mihalcea\\\/20\\\/a59\\\/580\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/vlad-mihalcea\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Spring request-level memoization","description":"Introduction Memoization is a method-level caching technique for speeding-up consecutive invocations. This post will demonstrate how you can achieve","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2014\/12\/spring-request-level-memoization.html","og_locale":"en_US","og_type":"article","og_title":"Spring request-level memoization","og_description":"Introduction Memoization is a method-level caching technique for speeding-up consecutive invocations. This post will demonstrate how you can achieve","og_url":"https:\/\/www.javacodegeeks.com\/2014\/12\/spring-request-level-memoization.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_author":"https:\/\/www.facebook.com\/vlad.mihalcea.71","article_published_time":"2014-12-03T08:00:18+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","type":"image\/jpeg"}],"author":"Vlad Mihalcea","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Vlad Mihalcea","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2014\/12\/spring-request-level-memoization.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/12\/spring-request-level-memoization.html"},"author":{"name":"Vlad Mihalcea","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/2c2d5059ee4fd88b1b3b9e52efc5b129"},"headline":"Spring request-level memoization","datePublished":"2014-12-03T08:00:18+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/12\/spring-request-level-memoization.html"},"wordCount":306,"commentCount":2,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/12\/spring-request-level-memoization.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","keywords":["Spring"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2014\/12\/spring-request-level-memoization.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2014\/12\/spring-request-level-memoization.html","url":"https:\/\/www.javacodegeeks.com\/2014\/12\/spring-request-level-memoization.html","name":"Spring request-level memoization","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/12\/spring-request-level-memoization.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/12\/spring-request-level-memoization.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","datePublished":"2014-12-03T08:00:18+00:00","description":"Introduction Memoization is a method-level caching technique for speeding-up consecutive invocations. This post will demonstrate how you can achieve","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2014\/12\/spring-request-level-memoization.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2014\/12\/spring-request-level-memoization.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2014\/12\/spring-request-level-memoization.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","width":150,"height":150,"caption":"spring-interview-questions-answers"},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2014\/12\/spring-request-level-memoization.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"Spring request-level memoization"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/2c2d5059ee4fd88b1b3b9e52efc5b129","name":"Vlad Mihalcea","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/f9f4ac0b2229b9f9fb993393b822ffbf63e60c1665a244176d3c4728565a9a9f?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/f9f4ac0b2229b9f9fb993393b822ffbf63e60c1665a244176d3c4728565a9a9f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/f9f4ac0b2229b9f9fb993393b822ffbf63e60c1665a244176d3c4728565a9a9f?s=96&d=mm&r=g","caption":"Vlad Mihalcea"},"description":"Vlad Mihalcea is a software architect passionate about software integration, high scalability and concurrency challenges.","sameAs":["http:\/\/vladmihalcea.wordpress.com\/","https:\/\/www.facebook.com\/vlad.mihalcea.71","http:\/\/www.linkedin.com\/pub\/vlad-mihalcea\/20\/a59\/580"],"url":"https:\/\/www.javacodegeeks.com\/author\/vlad-mihalcea"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/33847","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/507"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=33847"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/33847\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/240"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=33847"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=33847"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=33847"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}