{"id":37849,"date":"2024-11-26T13:33:15","date_gmt":"2024-11-26T05:33:15","guid":{"rendered":"https:\/\/fwq.ai\/blog\/37849\/"},"modified":"2024-11-26T13:33:15","modified_gmt":"2024-11-26T05:33:15","slug":"%e5%9c%a8-spring-boot-%e4%b8%ad%e9%80%9a%e8%bf%87%e7%bc%93%e5%ad%98%e6%8f%90%e9%ab%98%e5%90%8e%e7%ab%af%e6%80%a7%e8%83%bd","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/37849\/","title":{"rendered":"\u5728 Spring Boot \u4e2d\u901a\u8fc7\u7f13\u5b58\u63d0\u9ad8\u540e\u7aef\u6027\u80fd"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173146988871748.jpg\" class=\"aligncenter\" title=\"\u5728 Spring Boot \u4e2d\u901a\u8fc7\u7f13\u5b58\u63d0\u9ad8\u540e\u7aef\u6027\u80fd\u63d2\u56fe\" alt=\"\u5728 Spring Boot \u4e2d\u901a\u8fc7\u7f13\u5b58\u63d0\u9ad8\u540e\u7aef\u6027\u80fd\u63d2\u56fe\" \/><\/p>\n<p>\u5728\u5f53\u4eca\u4e16\u754c\uff0c\u5e94\u7528\u7a0b\u5e8f\u6027\u80fd\u81f3\u5173\u91cd\u8981\u3002\u7528\u6237\u671f\u671b\u5feb\u901f\u7684\u54cd\u5e94\u65f6\u95f4\uff0c\u5c24\u5176\u662f\u5728\u9ad8\u6d41\u91cf\u5e94\u7528\u7a0b\u5e8f\u4e2d\uff0c\u5ef6\u8fdf\u53ef\u80fd\u4f1a\u5f71\u54cd\u6216\u7834\u574f\u7528\u6237\u4f53\u9a8c\u3002\u7f13\u5b58\u662f\u589e\u5f3a\u540e\u7aef\u6027\u80fd\u7684\u6700\u6709\u6548\u65b9\u6cd5\u4e4b\u4e00\uff0c\u7279\u522b\u662f\u5728\u5904\u7406\u91cd\u590d\u6216\u6602\u8d35\u7684\u6570\u636e\u68c0\u7d22\u64cd\u4f5c\u65f6\u3002\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u5c06\u6df1\u5165\u63a2\u8ba8 spring boot \u7684\u7f13\u5b58\uff0c\u5e76\u8ba8\u8bba\u5404\u79cd\u7f13\u5b58\u7b56\u7565\u548c\u5b9e\u73b0\u6280\u5de7\uff0c\u4ee5\u63d0\u9ad8\u5e94\u7528\u7a0b\u5e8f\u7684\u901f\u5ea6\u3002<\/p>\n<h2> \u8981\u7f13\u5b58\uff1f <\/h2>\n<p>\u7f13\u5b58\u5141\u8bb8\u5e94\u7528\u7a0b\u5e8f\u4e34\u65f6\u5b58\u50a8\u6570\u636e\uff0c\u4ece\u800c\u51cf\u5c11\u4ece\u6570\u636e\u5e93\u6216\u5916\u90e8\u670d\u52a1\u68c0\u7d22\u9891\u7e41\u8bbf\u95ee\u7684\u6570\u636e\u6240\u9700\u7684\u65f6\u95f4\u3002\u901a\u8fc7\u51cf\u5c11\u76f4\u63a5\u6570\u636e\u5e93\u8bbf\u95ee\uff0c\u7f13\u5b58\u6709\u52a9\u4e8e\u964d\u4f4e\u670d\u52a1\u5668\u8d1f\u8f7d\u3001\u4f18\u5316\u7f51\u7edc\u4f7f\u7528\uff0c\u6700\u91cd\u8981\u7684\u662f\uff0c\u52a0\u5feb\u54cd\u5e94\u65f6\u95f4\u3002<\/p>\n<h2> \u7f13\u5b58\u7684\u5e38\u89c1\u7528\u4f8b\u5305\u62ec\uff1a <\/h2>\n<ul>\n<li>\u91cd\u590d\u83b7\u53d6\u9759\u6001\u6216\u5f88\u5c11\u66f4\u6539\u7684\u6570\u636e\u3002<\/li>\n<li>\u590d\u6742\u3001\u9ad8\u6210\u672c\u8ba1\u7b97\u7684\u5904\u7406\u7ed3\u679c\u3002<\/li>\n<li>\u5b58\u50a8\u7528\u6237\u4f1a\u8bdd\u6216\u8eab\u4efd\u9a8c\u8bc1\u4ee4\u724c\u3002<\/li>\n<li>\u5728 spring boot \u4e2d\u8bbe\u7f6e\u7f13\u5b58<\/li>\n<\/ul>\n<p>spring boot \u901a\u8fc7\u5229\u7528 @enablecaching \u6ce8\u91ca\u5e76\u4e3a\u7f13\u5b58\u7ba1\u7406\u63d0\u4f9b\u7b80\u5355\u7684\u62bd\u8c61\uff0c\u53ef\u4ee5\u8f7b\u677e\u5730\u5411\u5e94\u7528\u7a0b\u5e8f\u6dfb\u52a0\u7f13\u5b58\u3002<\/p>\n<h2> \u7b2c 1 \u6b65\uff1a\u5728 spring boot \u5e94\u7528\u7a0b\u5e8f\u4e2d\u542f\u7528\u7f13\u5b58 <\/h2>\n<p>\u9996\u5148\uff0c\u901a\u8fc7\u5c06 @enablecaching \u6dfb\u52a0\u5230\u60a8\u7684\u4e3b\u5e94\u7528\u7a0b\u5e8f\u7c7b\u6765\u542f\u7528\u7f13\u5b58\uff1a<\/p>\n<pre>@springbootapplication\n@enablecaching\npublic class application {\n    public static void main(string[] args) {\n        springapplication.run(application.class, args);\n    }\n}\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u5c06\u542f\u7528 spring \u7684\u7f13\u5b58\u57fa\u7840\u8bbe\u65bd\uff0c\u5b83\u5c06\u5728\u60a8\u7684\u65b9\u6cd5\u4e0a\u67e5\u627e\u7f13\u5b58\u6ce8\u91ca\u6765\u7ba1\u7406\u7f13\u5b58\u6761\u76ee\u3002<\/p>\n<h2> \u7b2c 2 \u6b65\uff1a\u6dfb\u52a0\u7f13\u5b58\u63d0\u4f9b\u7a0b\u5e8f <\/h2>\n<p>spring boot \u63d0\u4f9b\u4e86\u591a\u79cd\u7f13\u5b58\u63d0\u4f9b\u7a0b\u5e8f\uff0c\u5305\u62ec\uff1a<\/p>\n<p>concurrenthashmap\uff08\u9ed8\u8ba4\uff09\uff1a\u9002\u5408\u7b80\u5355\u5e94\u7528\u6216\u672c\u5730\u7f13\u5b58\u3002<br \/> ehcache\uff1a\u4e00\u79cd\u6d41\u884c\u7684\u5185\u5b58\u7f13\u5b58\uff0c\u5bf9 java \u5e94\u7528\u7a0b\u5e8f\u6709\u5f3a\u5927\u7684\u652f\u6301\u3002<br \/>\uff1a\u7531\u4e8e\u5176\u7f51\u7edc\u5316\u3001\u5185\u5b58\u6570\u636e\u7ed3\u6784\u529f\u80fd\uff0c\u975e\u5e38\u9002\u5408\u5206\u5e03\u5f0f\u5e94\u7528\u7a0b\u5e8f\u3002<br \/> hazelcast\u3001\u5496\u5561\u56e0\u3001memcached \u7b49<br \/> \u8ba9\u6211\u4eec\u5728\u8fd9\u91cc\u4f7f\u7528 redis \u4f5c\u4e3a\u6211\u4eec\u7684\u7f13\u5b58\u63d0\u4f9b\u8005\u3002\u5c06 redis \u4f9d\u8d56\u9879\u6dfb\u52a0\u5230\u60a8\u7684 pom.xml \u4e2d\uff1a<\/p>\n<pre>&lt;dependency&gt;\n    &lt;groupid&gt;org.springframework.boot&lt;\/groupid&gt;\n    &lt;artifactid&gt;spring-boot-starter-data-redis&lt;\/artifactid&gt;\n&lt;\/dependency&gt;\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728 application.properties \u6587\u4ef6\u4e2d\uff0c\u914d\u7f6e redis \u670d\u52a1\u5668\u8fde\u63a5\uff1a<\/p>\n<pre>spring.cache.type=redis\nspring.redis.host=localhost\nspring.redis.port=6379\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6ce8\u610f\uff1a\u8bf7\u786e\u4fdd\u60a8\u7684\u672c\u5730\u8ba1\u7b97\u673a\u4e0a\u6b63\u5728\u8fd0\u884c redis \u6216\u8fde\u63a5\u5230\u4e91 redis \u670d\u52a1\u3002<\/p>\n<h2> \u7b2c 3 \u6b65\uff1a\u5e94\u7528\u7f13\u5b58\u6ce8\u91ca <\/h2>\n<p>\u542f\u7528\u7f13\u5b58\u5e76\u914d\u7f6e\u63d0\u4f9b\u7a0b\u5e8f\u540e\uff0c\u60a8\u53ef\u4ee5\u5f00\u59cb\u5c06\u7f13\u5b58\u6ce8\u91ca\u5e94\u7528\u5230\u53d7\u76ca\u4e8e\u7f13\u5b58\u7684\u65b9\u6cd5\u3002\u6700\u5e38\u7528\u7684\u6ce8\u89e3\u662f@cacheable\u3002<\/p>\n<p>@cacheable \u793a\u4f8b<\/p>\n<p>\u5728\u65b9\u6cd5\u4e0a\u4f7f\u7528@cacheable\u5c06\u7ed3\u679c\u5b58\u50a8\u5728\u7f13\u5b58\u4e2d\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528\u83b7\u53d6\u7528\u6237\u6570\u636e\u7684\u670d\u52a1\u7684\u793a\u4f8b\uff1a<\/p>\n<pre>@service\npublic class userservice {\n\n    @cacheable(value = \"users\", key = \"#userid\")\n    public user getuserbyid(long userid) {\n        \/\/ simulate a costly operation, like a database call\n        simulateslowservice();\n        return new user(userid, \"john doe\");\n    }\n\n    private void simulateslowservice() {\n        try {\n            thread.sleep(3000); \/\/ simulate a 3-second delay\n        } catch (interruptedexception e) {\n            throw new illegalstateexception(e);\n        }\n    }\n}\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0cgetuserbyid\u65b9\u6cd5\u88ab\u7f13\u5b58\uff0c\u901a\u8fc7userid\u5c06\u7528\u6237\u5bf9\u8c61\u5b58\u50a8\u5728\u201cusers\u201d\u7f13\u5b58\u4e2d\u3002\u4f7f\u7528\u76f8\u540c userid \u7684\u540e\u7eed\u8c03\u7528\u5c06\u8fd4\u56de\u7f13\u5b58\u7684\u503c\uff0c\u4ece\u800c\u7ed5\u8fc7simulateslowservice() \u5ef6\u8fdf\u3002<\/p>\n<p>\u4f7f\u7528@cacheput\u548c@cacheevict<\/p>\n<p>@cacheput\uff1a\u66f4\u65b0\u7f13\u5b58\u800c\u4e0d\u8df3\u8fc7\u65b9\u6cd5\u6267\u884c\u3002<br \/> @cacheevict\uff1a\u4ece\u7f13\u5b58\u4e2d\u5220\u9664\u4e00\u4e2a\u6761\u76ee\uff0c\u5bf9\u4e8e\u4fdd\u6301\u7f13\u5b58\u6570\u636e\u65b0\u9c9c\u5f88\u6709\u7528\u3002<br \/> \u4f8b\u5982\uff0c\u66f4\u65b0\u6216\u5220\u9664\u7528\u6237\u65f6\u4f7f\u7528@cacheevict\uff1a<\/p>\n<pre>@cacheevict(value = \"users\", key = \"#userid\")\npublic void deleteuser(long userid) {\n    \/\/ code to delete user from the database\n}\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u7f13\u5b58\u7b56\u7565<br \/> \u4e3a\u4e86\u5145\u5206\u5229\u7528\u7f13\u5b58\uff0c\u9009\u62e9\u6b63\u786e\u7684\u7f13\u5b58\u7b56\u7565\u81f3\u5173\u91cd\u8981\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u9700\u8981\u8003\u8651\u7684\u65b9\u6cd5\uff1a<\/p>\n<h2> 1. \u751f\u5b58\u65f6\u95f4 (ttl) \u7f13\u5b58 <\/h2>\n<p>\u914d\u7f6e\u7f13\u5b58\u6761\u76ee\u7684 ttl\uff0c\u4f7f\u5176\u5728\u8bbe\u5b9a\u7684\u65f6\u95f4\u6bb5\u540e\u81ea\u52a8\u8fc7\u671f\u3002\u8fd9\u53ef\u4ee5\u9632\u6b62\u8fc7\u65f6\u7684\u6570\u636e\u5728\u7f13\u5b58\u4e2d\u5f98\u5f8a\uff0c\u8fd9\u5bf9\u4e8e\u9891\u7e41\u66f4\u65b0\u7684\u6570\u636e\u7279\u522b\u6709\u7528\u3002<\/p>\n<p>\u5728 redis \u4e2d\uff0c\u60a8\u53ef\u4ee5\u5728\u914d\u7f6e\u4e2d\u6309\u5982\u4e0b\u65b9\u5f0f\u8bbe\u7f6e ttl\uff1a<\/p>\n<pre>@Bean\npublic RedisCacheConfiguration cacheConfiguration() {\n    return RedisCacheConfiguration.defaultCacheConfig()\n        .entryTtl(Duration.ofMinutes(10)) \/\/ Set TTL for 10 minutes\n        .disableCachingNullValues();\n}\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h2> 2. \u7f13\u5b58\u7aef\u6a21\u5f0f <\/h2>\n<p>\u5728\u6b64\u6a21\u5f0f\u4e2d\uff0c\u5e94\u7528\u7a0b\u5e8f\u5728\u4ece\u6570\u636e\u5e93\u68c0\u7d22\u6570\u636e\u4e4b\u524d\u68c0\u67e5\u7f13\u5b58\u3002\u5982\u679c\u5728\u7f13\u5b58\u4e2d\u627e\u4e0d\u5230\u6570\u636e\uff08\u201c\u7f13\u5b58\u672a\u547d\u4e2d\u201d\uff09\uff0c\u5b83\u5c06\u4ece\u6570\u636e\u5e93\u4e2d\u83b7\u53d6\u3001\u7f13\u5b58\u7ed3\u679c\u5e76\u8fd4\u56de\u3002\u8fd9\u662f\u4e00\u79cd\u5e38\u89c1\u7684\u65b9\u6cd5\uff0c\u5e76\u4e14\u4f7f\u7528 @cacheable \u5b9e\u73b0\u8d77\u6765\u5f88\u7b80\u5355\u3002<\/p>\n<h2> 3. \u76f4\u5199\u5f0f\u548c\u540e\u5199\u5f0f\u7f13\u5b58 <\/h2>\n<p>write-through\uff1a\u7f13\u5b58\u4e0e\u6570\u636e\u5e93\u540c\u65f6\u66f4\u65b0\u3002<br \/> write-behind\uff1a\u7f13\u5b58\u7acb\u5373\u66f4\u65b0\uff0c\u4f46\u6570\u636e\u5e93\u7a0d\u540e\u6279\u91cf\u66f4\u65b0\u3002<br \/> \u5f53\u60a8\u5e0c\u671b\u7f13\u5b58\u548c\u6570\u636e\u5e93\u4e4b\u95f4\u7684\u6570\u636e\u4fdd\u6301\u4e00\u81f4\u65f6\uff0c\u8fd9\u4e9b\u65b9\u6cd5\u975e\u5e38\u6709\u7528\u3002<\/p>\n<h2> \u76d1\u63a7\u7f13\u5b58\u6027\u80fd <\/h2>\n<p>\u76d1\u63a7\u7f13\u5b58\u6027\u80fd\u4ee5\u786e\u4fdd\u5176\u63d0\u4f9b\u9884\u671f\u7684\u597d\u5904\u81f3\u5173\u91cd\u8981\u3002\u60a8\u53ef\u4ee5\u8ddf\u8e2a\u7f13\u5b58\u547d\u4e2d\u3001\u672a\u547d\u4e2d\u548c\u9010\u51fa\uff0c\u4ee5\u8bc6\u522b\u4efb\u4f55\u74f6\u9888\u3002\u5e38\u7528\u7684\u76d1\u63a7\u5de5\u5177\u5305\u62ec\uff1a<\/p>\n<ol>\n<li>redis cli\uff1a\u5b9e\u65f6\u76d1\u63a7 redis \u7f13\u5b58\u547d\u4e2d\/\u672a\u547d\u4e2d\u3002<\/li>\n<li>spring boot actuator\uff1a\u516c\u5f00\u7f13\u5b58\u6307\u6807\u4ee5\u8fdb\u884c\u76d1\u63a7\u548c\u7ba1\u7406\u3002<\/li>\n<li>prometheus \u548c grafana\uff1a\u8ddf\u8e2a\u548c\u53ef\u89c6\u5316 redis \u548c spring boot \u6307\u6807\u3002<\/li>\n<\/ol>\n<h2> \u8981\u907f\u514d\u7684\u5e38\u89c1\u7f13\u5b58\u9677\u9631 <\/h2>\n<ol>\n<li>\u7f13\u5b58\u592a\u591a\u6570\u636e\uff1a\u7f13\u5b58\u8fc7\u5927\u7684\u6570\u636e\u53ef\u80fd\u4f1a\u5bfc\u81f4\u5185\u5b58\u4f7f\u7528\u7387\u8fc7\u9ad8\uff0c\u4ece\u800c\u62b5\u6d88\u6027\u80fd\u63d0\u5347\u3002<\/li>\n<li>\u4e0d\u9891\u7e41\u8bbf\u95ee\uff1a\u7f13\u5b58\u5f88\u5c11\u8bbf\u95ee\u7684\u6570\u636e\u53ef\u80fd\u4e0d\u503c\u5f97\uff0c\u56e0\u4e3a\u5b83\u4e0d\u4f1a\u663e\u7740\u51cf\u5c11\u68c0\u7d22\u65f6\u95f4\u3002<\/li>\n<li>\u8fc7\u65f6\u6570\u636e\u95ee\u9898\uff1a\u5982\u679c\u6570\u636e\u9891\u7e41\u66f4\u6539\uff0c\u8bf7\u8bbe\u7f6e ttl \u4ee5\u907f\u514d\u63d0\u4f9b\u8fc7\u65f6\u7684\u4fe1\u606f\u3002<\/li>\n<\/ol>\n<p>\u7f13\u5b58\u662f\u589e\u5f3a\u540e\u7aef\u6027\u80fd\u7684\u5f3a\u5927\u5de5\u5177\uff0cspring boot \u4f7f\u5176\u6613\u4e8e\u5b9e\u73b0\u3002\u901a\u8fc7\u5229\u7528 @cacheable\u3001@cacheevict \u7b49\u7f13\u5b58\u6ce8\u91ca\u5e76\u4f7f\u7528\u5408\u9002\u7684\u7f13\u5b58\u7b56\u7565\uff0c\u60a8\u53ef\u4ee5\u663e\u7740\u7f29\u77ed\u54cd\u5e94\u65f6\u95f4\u3001\u964d\u4f4e\u670d\u52a1\u5668\u8d1f\u8f7d\u5e76\u6539\u5584\u6574\u4f53\u7528\u6237\u4f53\u9a8c\u3002\u65e0\u8bba\u60a8\u4f7f\u7528 redis\u3001ehcache \u8fd8\u662f\u5176\u4ed6\u7f13\u5b58\u63d0\u4f9b\u7a0b\u5e8f\uff0c\u7f13\u5b58\u5bf9\u4e8e\u4efb\u4f55\u9ad8\u6027\u80fd\u5e94\u7528\u7a0b\u5e8f\u90fd\u662f\u4e00\u4e2a\u6709\u4ef7\u503c\u7684\u8865\u5145\u3002<\/p>\n<p>\u5f00\u59cb\u5728 spring boot \u5e94\u7528\u7a0b\u5e8f\u4e2d\u5c1d\u8bd5\u7f13\u5b58\uff0c\u5e76\u89c2\u5bdf\u6027\u80fd\u7684\u63d0\u9ad8\uff01<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5728 Spring Boot \u4e2d\u901a\u8fc7\u7f13\u5b58\u63d0\u9ad8\u540e\u7aef\u6027\u80fd\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u5f53\u4eca\u4e16\u754c\uff0c\u5e94\u7528\u7a0b\u5e8f\u6027\u80fd\u81f3\u5173\u91cd\u8981\u3002\u7528\u6237\u671f\u671b\u5feb\u901f\u7684\u54cd\u5e94\u65f6\u95f4\uff0c\u5c24\u5176\u662f\u5728\u9ad8\u6d41\u91cf\u5e94\u7528\u7a0b\u5e8f\u4e2d\uff0c\u5ef6\u8fdf\u53ef\u80fd\u4f1a\u5f71\u54cd\u6216\u7834\u574f\u7528\u6237\u4f53\u9a8c\u3002\u7f13\u5b58\u662f\u589e\u5f3a\u540e\u7aef\u6027\u80fd\u7684\u6700\u6709\u6548\u65b9\u6cd5\u4e4b\u4e00\uff0c\u7279\u522b\u662f\u5728\u5904\u7406\u91cd\u590d\u6216\u6602\u8d35\u7684\u6570\u636e\u68c0\u7d22\u64cd\u4f5c\u65f6\u3002\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u5c06\u6df1\u5165\u63a2\u8ba8 spring boot \u7684\u7f13\u5b58\uff0c\u5e76\u8ba8\u8bba\u5404\u79cd\u7f13\u5b58\u7b56\u7565\u548c\u5b9e\u73b0\u6280\u5de7\uff0c\u4ee5\u63d0\u9ad8\u5e94\u7528\u7a0b\u5e8f\u7684\u901f\u5ea6\u3002 \u8981\u7f13\u5b58\uff1f \u7f13\u5b58\u5141\u8bb8\u5e94\u7528\u7a0b\u5e8f\u4e34\u65f6\u5b58\u50a8\u6570\u636e\uff0c\u4ece\u800c\u51cf\u5c11\u4ece\u6570\u636e\u5e93\u6216\u5916\u90e8\u670d\u52a1\u68c0\u7d22\u9891\u7e41\u8bbf\u95ee\u7684\u6570\u636e\u6240\u9700\u7684\u65f6\u95f4\u3002\u901a\u8fc7\u51cf\u5c11\u76f4\u63a5\u6570\u636e\u5e93\u8bbf\u95ee\uff0c\u7f13\u5b58\u6709\u52a9\u4e8e\u964d\u4f4e\u670d\u52a1\u5668\u8d1f\u8f7d\u3001\u4f18\u5316\u7f51\u7edc\u4f7f\u7528\uff0c\u6700\u91cd\u8981\u7684\u662f\uff0c\u52a0\u5feb\u54cd\u5e94\u65f6\u95f4\u3002 \u7f13\u5b58\u7684\u5e38\u89c1\u7528\u4f8b\u5305\u62ec\uff1a \u91cd\u590d\u83b7\u53d6\u9759\u6001\u6216\u5f88\u5c11\u66f4\u6539\u7684\u6570\u636e\u3002 \u590d\u6742\u3001\u9ad8\u6210\u672c\u8ba1\u7b97\u7684\u5904\u7406\u7ed3\u679c\u3002 \u5b58\u50a8\u7528\u6237\u4f1a\u8bdd\u6216\u8eab\u4efd\u9a8c\u8bc1\u4ee4\u724c\u3002 \u5728 spring boot \u4e2d\u8bbe\u7f6e\u7f13\u5b58 spring boot \u901a\u8fc7\u5229\u7528 @enablecaching \u6ce8\u91ca\u5e76\u4e3a\u7f13\u5b58\u7ba1\u7406\u63d0\u4f9b\u7b80\u5355\u7684\u62bd\u8c61\uff0c\u53ef\u4ee5\u8f7b\u677e\u5730\u5411\u5e94\u7528\u7a0b\u5e8f\u6dfb\u52a0\u7f13\u5b58\u3002 \u7b2c 1 \u6b65\uff1a\u5728 spring boot \u5e94\u7528\u7a0b\u5e8f\u4e2d\u542f\u7528\u7f13\u5b58 \u9996\u5148\uff0c\u901a\u8fc7\u5c06 @enablecaching \u6dfb\u52a0\u5230\u60a8\u7684\u4e3b\u5e94\u7528\u7a0b\u5e8f\u7c7b\u6765\u542f\u7528\u7f13\u5b58\uff1a @springbootapplication @enablecaching public class application { public static void main(string[] args) { springapplication.run(application.class, args); } } \u767b\u5f55\u540e\u590d\u5236 \u8fd9\u5c06\u542f\u7528 spring \u7684\u7f13\u5b58\u57fa\u7840\u8bbe\u65bd\uff0c\u5b83\u5c06\u5728\u60a8\u7684\u65b9\u6cd5\u4e0a\u67e5\u627e\u7f13\u5b58\u6ce8\u91ca\u6765\u7ba1\u7406\u7f13\u5b58\u6761\u76ee\u3002 \u7b2c 2 \u6b65\uff1a\u6dfb\u52a0\u7f13\u5b58\u63d0\u4f9b\u7a0b\u5e8f spring boot \u63d0\u4f9b\u4e86\u591a\u79cd\u7f13\u5b58\u63d0\u4f9b\u7a0b\u5e8f\uff0c\u5305\u62ec\uff1a concurrenthashmap\uff08\u9ed8\u8ba4\uff09\uff1a\u9002\u5408\u7b80\u5355\u5e94\u7528\u6216\u672c\u5730\u7f13\u5b58\u3002 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-37849","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/37849","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=37849"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/37849\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=37849"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=37849"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=37849"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}