{"id":192,"date":"2020-03-15T15:06:28","date_gmt":"2020-03-15T06:06:28","guid":{"rendered":"http:\/\/www.skyer9.pe.kr\/wordpress\/?p=192"},"modified":"2021-07-30T13:41:11","modified_gmt":"2021-07-30T04:41:11","slug":"from-hello-to-querydsl-cache-with-redis-8-12","status":"publish","type":"post","link":"https:\/\/www.skyer9.pe.kr\/wordpress\/?p=192","title":{"rendered":"[From Hello To QueryDSL] Cache with Redis (8\/12)"},"content":{"rendered":"<h1>Cache with Redis<\/h1>\n<p>Redis \uae30\ubc18\uc73c\ub85c \uce90\uc2dc \uae30\ub2a5\uc744 \uc124\uc815\ud569\ub2c8\ub2e4.<\/p>\n<h2>\uac1c\ubc1c\ud658\uacbd<\/h2>\n<ul>\n<li>Spring Boot 2.1.x<\/li>\n<li>Gradle 4.10.2<\/li>\n<\/ul>\n<h2>\ud30c\uc77c\ucd94\uac00 \ubc0f \uc218\uc815<\/h2>\n<p>build.gradle<\/p>\n<pre><code class=\"language-configuration\">......\ndependencies {\n    \/\/ ......\n    implementation &#039;org.springframework.boot:spring-boot-starter-data-redis&#039;\n    implementation &#039;org.springframework.boot:spring-boot-starter-cache&#039;\n    \/\/ ......\n}\n......<\/code><\/pre>\n<p>src\/main\/java\/kr\/co\/episode\/example\/config\/CacheConfig.java<\/p>\n<pre><code class=\"language-java\">@Configuration\n@EnableCaching\npublic class CacheConfig {\n}<\/code><\/pre>\n<p><code>@Cacheable<\/code> \uc5b4\ub178\ud14c\uc774\uc158\uc744 \ucd94\uac00\ud569\ub2c8\ub2e4.<\/p>\n<p>src\/main\/java\/kr\/co\/episode\/example\/service\/posts\/PostsPagingService.java<\/p>\n<pre><code class=\"language-java\">    \/\/ ......\n    @Transactional(readOnly = true)\n    @Cacheable(value=&quot;Posts&quot;)\n    public Page&lt;PostsListResponseDto&gt; search(Pageable pageable, PostsSearchDto postsSearchDto) {\n        \/\/ ......\n    }\n    \/\/ ......<\/code><\/pre>\n<p><code>@ToString<\/code> \uc5b4\ub178\ud14c\uc774\uc158\uc744 \ucd94\uac00\ud569\ub2c8\ub2e4. \uc774\uac83\ub54c\ubb38\uc5d0 \uaf64 \uace0\uc0dd\ud588\ub294\ub370&#8230; \uc774\uc720\ub97c \uc124\uba85\ud569\ub2c8\ub2e4.<\/p>\n<p>\uce90\uc2dc\ub294 \uae30\ubcf8\uc801\uc73c\ub85c key-value \uae30\ubc18\uc785\ub2c8\ub2e4. \uadf8\ub7fc \uc704\uc5d0 \uce90\uc2dc \ud558\ub824\ub294 \uba54\uc18c\ub4dc\uc5d0\uc11c key \ub294 \uc5b4\ub5bb\uac8c \uc790\ub3d9\uc0dd\uc131\ub420\uae4c\uc694? \ud30c\ub77c\ubbf8\ud130 \uae30\ubc18\uc73c\ub85c key \ub97c \uc0dd\uc131\ud560\uac81\ub2c8\ub2e4.<\/p>\n<p>\uadf8\ub7fc \ud074\ub798\uc2a4\uac00 \uc5b4\ub5bb\uac8c key \uac00 \ub420\uae4c\uc694? <code>toString()<\/code> \uc73c\ub85c key \ub97c \uc0dd\uc131\ud560\uac81\ub2c8\ub2e4. <code>toString()<\/code> \uc774 \uc5c6\ub2e4\uba74? \uadf8\ub7fc key \ub97c \uc218\ub3d9\uc73c\ub85c \uc0dd\uc131\ud574 \uc8fc\uac70\ub098, \uc544\ub2c8\uba74 key \ub97c \uc0dd\uc131\ud560 \uc218 \uc5c6\uace0&#8230; \uce90\uc2dc \uae30\ub2a5\uc774 \uc791\ub3d9\ud558\uc9c0 \uc54a\uc2b5\ub2c8\ub2e4.<\/p>\n<p>\ud074\ub798\uc2a4\uac00 \uc0c1\uc18d\uc744 \ubc1b\uc740 \uacbd\uc6b0, \uc0c1\uc704 \ud074\ub798\uc2a4 \ubaa8\ub450\uc5d0 <code>@ToString<\/code> \uc774 \uc788\uc5b4\uc57c \ud569\ub2c8\ub2e4.<\/p>\n<p>src\/main\/java\/kr\/co\/episode\/example\/web\/dto\/PostsSearchDto.java<\/p>\n<pre><code class=\"language-java\">@ToString\n@Getter\npublic class PostsSearchDto {\n    \/\/ ......\n}<\/code><\/pre>\n<p><code>@CacheEvict<\/code> \uc740 \uce90\uc2dc\ub97c \uc0ad\uc81c\ud569\ub2c8\ub2e4.<\/p>\n<p>src\/main\/java\/kr\/co\/episode\/example\/service\/posts\/PostsService.java<\/p>\n<pre><code class=\"language-java\">\npublic class PostsService {\n    \/\/ ......\n    @Transactional\n    @CacheEvict(value=&quot;Posts&quot;)\n    public Long update(Long id, PostsUpdateRequestDto postsUpdateRequestDto) {\n        \/\/ ......\n    }\n\n    @Cacheable(value=&quot;Posts&quot;)\n    public PostsResponseDto findById(Long id) {\n        \/\/ ......\n    }\n\n    @Transactional\n    @CacheEvict(value=&quot;Posts&quot;)\n    public void delete(Long id) {\n        \/\/ ......\n    }\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Redis \uae30\ubc18\uc73c\ub85c \uce90\uc2dc \uae30\ub2a5\uc744 \uc124\uc815\ud569\ub2c8\ub2e4.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-192","post","type-post","status-publish","format-standard","hentry","category-spring-boot-2-1"],"_links":{"self":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/192","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=192"}],"version-history":[{"count":11,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/192\/revisions"}],"predecessor-version":[{"id":2492,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/192\/revisions\/2492"}],"wp:attachment":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=192"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=192"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=192"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}