{"id":2181,"date":"2021-07-15T19:09:33","date_gmt":"2021-07-15T10:09:33","guid":{"rendered":"https:\/\/www.skyer9.pe.kr\/wordpress\/?p=2181"},"modified":"2021-07-15T17:18:59","modified_gmt":"2021-07-15T08:18:59","slug":"ehcache-%ec%84%a4%ec%a0%95%eb%b2%95","status":"publish","type":"post","link":"https:\/\/www.skyer9.pe.kr\/wordpress\/?p=2181","title":{"rendered":"Ehcache \uc124\uc815\ubc95"},"content":{"rendered":"<h1>Ehcache \uc124\uc815\ubc95<\/h1>\n<h2>\uc758\uc874\uc131 \ucd94\uac00<\/h2>\n<pre><code class=\"language-gradle\">dependencies {\n    implementation &#039;org.springframework.boot:spring-boot-starter-cache&#039;\n    implementation &#039;org.ehcache:ehcache&#039;\n    implementation &#039;javax.cache:cache-api&#039;\n}<\/code><\/pre>\n<h2>\uc124\uc815\ud30c\uc77c \ucd94\uac00<\/h2>\n<p>resources \ud3f4\ub354\uc5d0 ehcache.xml \uc744 \ucd94\uac00\ud55c\ub2e4.<\/p>\n<p>\ub85c\uadf8 \ud655\uc778\uc774 \ubd88\ud544\uc694\ud55c \uacbd\uc6b0 listeners \ub294 \uc81c\uac70\ud55c\ub2e4.<\/p>\n<p>searchOrderMaster \ub294 \uc790\ubc14 \uc18c\uc2a4\uc0c1\uc758 \uce90\uc2dc\uba85\uacfc \uac19\uc544\uc57c \ud55c\ub2e4.<\/p>\n<pre><code class=\"language-xml\">&lt;config xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot;\n        xmlns=&quot;http:\/\/www.ehcache.org\/v3&quot;\n        xsi:schemaLocation=&quot;http:\/\/www.ehcache.org\/v3 http:\/\/www.ehcache.org\/schema\/ehcache-core-3.0.xsd&quot;&gt;\n\n    &lt;cache alias=&quot;searchOrderMaster&quot;&gt; &lt;!-- cache \uc694\uc18c\ub294 CachceManager\uc5d0 \uc758\ud574 \uc791\uc131\ub418\uace0 \uad00\ub9ac\ub420 Cache \uc778\uc2a4\ud134\uc2a4\ub97c \ub098\ud0c0\ub0b8\ub2e4. Cache&lt;k,v&gt; \ud615\ud0dc\ub85c \uc778\uc2a4\ud134\uc2a4\uac00 \uc0dd\uc131\ub41c\ub2e4. alias\uc5d0\ub294 \uce90\uc2dc\uc758 \uc774\ub984\uc744 \uc9c0\uc815\ud55c\ub2e4. --&gt;\n        &lt;key-type&gt;java.util.Map&lt;\/key-type&gt; &lt;!-- key-type \uc694\uc18c\ub294 Cache \uc778\uc2a4\ud134\uc2a4\uc5d0 \uc800\uc7a5\ub420 \uce90\uc2dc\uc758 \ud0a4\uc758 FQCN\uc744 \uc9c0\uc815\ud55c\ub2e4. \uc989, \ud0a4\uc758 \ud0c0\uc785\uc744 \uba85\uc2dc\ud574\uc8fc\uba74 \ub41c\ub2e4. \uae30\ubcf8 \uac12\uc740 java.lang.Object \uc774\ub2e4. --&gt;\n        &lt;value-type&gt;kr.tenbyten.csapi.web.dto.SearchResponseDto&lt;\/value-type&gt; &lt;!-- value-type \uc694\uc18c\ub294 Cache \uc778\uc2a4\ud134\uc2a4\uc5d0 \uc800\uc7a5\ub41c \uac12\uc758 FQCN\uc744 \uc9c0\uc815\ud55c\ub2e4. \uae30\ubcf8 \uac12\uc740 java.lang.Object \uc774\ub2e4. --&gt;\n        &lt;expiry&gt; &lt;!-- expiry\ub294 \uce90\uc2dc \ub9cc\ub8cc\uae30\uac04\uc5d0 \ub300\ud574 \uc124\uc815\ud558\ub294 \uc694\uc18c\uc774\ub2e4. --&gt;\n            &lt;ttl unit=&quot;seconds&quot;&gt;3&lt;\/ttl&gt; &lt;!-- ttl\uc5d0\ub294 \uce90\uc2dc \ub9cc\ub8cc \uc2dc\uac04\uc744 \uc9c0\uc815\ud558\uba70 unit\uc5d0\ub294 \ub2e8\uc704\ub97c \uc9c0\uc815\ud55c\ub2e4. \ud574\ub2f9 \uc694\uc18c\ub294 30\ucd08 \ub4a4 \uce90\uc2dc\uac00 \ub9cc\ub8cc\ub418\ub294 \uac83\uc73c\ub85c \uc9c0\uc815\ub418\uc5b4 \uc788\ub2e4. --&gt;\n            &lt;!-- unit\uc740 days, hours, minutes, seconds, millis, micros, nanos \ub97c \uc138\ud305\ud560 \uc218 \uc788\ub2e4. --&gt;\n        &lt;\/expiry&gt;\n\n        &lt;listeners&gt;\n            &lt;listener&gt;\n                &lt;class&gt;kr.tenbyten.csapi.config.CacheEventLogger&lt;\/class&gt;\n                &lt;event-firing-mode&gt;ASYNCHRONOUS&lt;\/event-firing-mode&gt;\n                &lt;event-ordering-mode&gt;UNORDERED&lt;\/event-ordering-mode&gt;\n                &lt;events-to-fire-on&gt;CREATED&lt;\/events-to-fire-on&gt;\n                &lt;events-to-fire-on&gt;EXPIRED&lt;\/events-to-fire-on&gt;\n            &lt;\/listener&gt;\n        &lt;\/listeners&gt;\n\n        &lt;resources&gt; &lt;!-- resources\ub294 \uce90\uc2dc \ub370\uc774\ud130\uc758 \uc800\uc7a5 \uacf5\uac04\uacfc \uc6a9\ub7c9\uc744 \uc9c0\uc815\ud55c\ub2e4. \ub9cc\uc57d \ud799 \uba54\ubaa8\ub9ac\ub9cc \uc0ac\uc6a9\ud55c\ub2e4\uba74 &lt;heap&gt; \uc694\uc18c\ub9cc\uc73c\ub85c \ub300\uccb4\ud560 \uc218 \uc788\ub2e4.  --&gt;\n            &lt;heap unit=&quot;entries&quot;&gt;2&lt;\/heap&gt; &lt;!-- heap\uc740 JVM \ud799 \uba54\ubaa8\ub9ac\uc5d0 \uce90\uc2dc\ub97c \uc800\uc7a5\ud558\ub3c4\ub85d \uc138\ud305\ud558\ub294 \uc694\uc18c\uc774\ub2e4. --&gt;\n            &lt;offheap unit=&quot;MB&quot;&gt;10&lt;\/offheap&gt; &lt;!-- offheap\uc740 JVM \ud799 \uba54\ubaa8\ub9ac \uc678\ubd80\uc758 \uba54\ubaa8\ub9ac\uc5d0 \uce90\uc2dc\ub97c \uc800\uc7a5\ud558\ub3c4\ub85d \uc138\ud305\ud558\ub294 \uc694\uc18c\uc774\ub2e4. --&gt;\n        &lt;\/resources&gt;\n    &lt;\/cache&gt;\n\n&lt;\/config&gt;<\/code><\/pre>\n<p>application.yml \ud30c\uc77c\uc5d0 \uc544\ub798 \ub0b4\uc6a9\uc744 \ucd94\uac00\ud574\uc900\ub2e4.<\/p>\n<pre><code>spring:\n  cache:\n    jcache:\n      config: classpath:ehcache.xml<\/code><\/pre>\n<h2>\uce90\uc2dc \ud65c\uc131\ud654<\/h2>\n<p>\uc544\ub798 \ud30c\uc77c\uc744 \uc0dd\uc131\ud574\uc11c \uce90\uc2dc\ub97c \ud65c\uc131\ud654 \ud574\uc900\ub2e4.<\/p>\n<pre><code class=\"language-java\">@Configuration\n@EnableCaching\npublic class CacheConfig {\n}<\/code><\/pre>\n<h2>\ub85c\uadf8 \ud65c\uc131\ud654<\/h2>\n<p>\ub85c\uae45\uc774 \ud544\uc694\ud55c \uacbd\uc6b0 \uc544\ub798 \ud30c\uc77c\uc744 \ucd94\uac00\ud574\uc900\ub2e4.<\/p>\n<pre><code class=\"language-java\">@Slf4j\npublic class CacheEventLogger implements CacheEventListener&lt;Object, Object&gt; {\n\n    public void onEvent(CacheEvent&lt;? extends Object, ? extends Object&gt; cacheEvent) {\n        log.info(&quot;=================&gt;&gt; getKey: {} \/ getOldValue: {} \/ getNewValue:{}&quot;, cacheEvent.getKey(), cacheEvent.getOldValue(), cacheEvent.getNewValue());\n    }\n}<\/code><\/pre>\n<h2>\uce90\uc2dc \uc801\uc6a9<\/h2>\n<pre><code class=\"language-java\">@RequiredArgsConstructor\n@Service\npublic class OrderMasterService {\n\n    @Cacheable(value = &quot;searchOrderMaster&quot;, key = &quot;#params&quot;)\n    @Transactional(readOnly = true)\n    public SearchResponseDto search(Map&lt;String, String&gt; params) { ... }\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Ehcache \uc124\uc815\ubc95 \uc758\uc874\uc131 \ucd94\uac00 dependencies { implementation &#039;org.springframework.boot:spring-boot-starter-cache&#039; implementation &#039;org.ehcache:ehcache&#039; implementation &#039;javax.cache:cache-api&#039; } \uc124\uc815\ud30c\uc77c \ucd94\uac00 resources \ud3f4\ub354\uc5d0 ehcache.xml \uc744 \ucd94\uac00\ud55c\ub2e4. \ub85c\uadf8 \ud655\uc778\uc774 \ubd88\ud544\uc694\ud55c \uacbd\uc6b0 listeners \ub294 \uc81c\uac70\ud55c\ub2e4. searchOrderMaster \ub294 \uc790\ubc14 \uc18c\uc2a4\uc0c1\uc758 \uce90\uc2dc\uba85\uacfc \uac19\uc544\uc57c \ud55c\ub2e4. &lt;config xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot; xmlns=&quot;http:\/\/www.ehcache.org\/v3&quot; xsi:schemaLocation=&quot;http:\/\/www.ehcache.org\/v3 http:\/\/www.ehcache.org\/schema\/ehcache-core-3.0.xsd&quot;&gt; &lt;cache alias=&quot;searchOrderMaster&quot;&gt; &lt;!&#8211; cache \uc694\uc18c\ub294 CachceManager\uc5d0 \uc758\ud574 \uc791\uc131\ub418\uace0 \uad00\ub9ac\ub420 Cache \uc778\uc2a4\ud134\uc2a4\ub97c \ub098\ud0c0\ub0b8\ub2e4. Cache&lt;k,v&gt; \ud615\ud0dc\ub85c \uc778\uc2a4\ud134\uc2a4\uac00 \uc0dd\uc131\ub41c\ub2e4.\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.skyer9.pe.kr\/wordpress\/?p=2181\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2181","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/2181","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2181"}],"version-history":[{"count":1,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/2181\/revisions"}],"predecessor-version":[{"id":2182,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/2181\/revisions\/2182"}],"wp:attachment":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2181"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2181"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2181"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}