Skip to content

Commit

Permalink
#561 [fix] Cache 동시성 이슈 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
sohyundoh committed Oct 30, 2024
1 parent bc3f1e2 commit b274155
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,24 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.Objects;

@Embeddable
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class MoimCuriousPost {
private Long postId;
private String title;
private String idUrl;
private String contents;
private String imgUrl;
private String topic;
private boolean isContainPhoto;

public static MoimCuriousPost of(final Post post) {
return new MoimCuriousPost(
post.getId(),
post.getTitle(),
post.getIdUrl(),
post.getContent(),
Expand All @@ -28,4 +33,16 @@ public static MoimCuriousPost of(final Post post) {
post.isContainPhoto()
);
}

@Override
public int hashCode() {
return postId.intValue();
}

@Override
public boolean equals(Object target) {
MoimCuriousPost targetPost = (MoimCuriousPost) target;

return Objects.equals(this.postId, targetPost.postId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,34 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.Objects;

@Embeddable
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class MoimCuriousWriter {
Long writerNameId;
String name;

private MoimCuriousWriter(final String name) {

private MoimCuriousWriter(final Long writerNameId, final String name) {
this.writerNameId = writerNameId;
this.name = name;
}

public static MoimCuriousWriter of(final WriterName writerName) {
return new MoimCuriousWriter(writerName.getName());
return new MoimCuriousWriter(writerName.getId(), writerName.getName());
}

@Override
public int hashCode() {
return writerNameId.intValue();
}

@Override
public boolean equals(Object target) {
MoimCuriousWriter targetWriter = (MoimCuriousWriter) target;

return Objects.equals(this.name, targetWriter.name) && Objects.equals(this.writerNameId, targetWriter.writerNameId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public class MoimPopularInfoService {


@Cacheable(value = "moimPopularInfo", key = "#moim.id")
@AtomicValidateMoimPopulerInfo
public MoimPopularInfo getMoimPopularInfo(final Moim moim) {
return moimPopularInfoRepository.findByMoimId(moim.getId()).orElseGet(
() -> moimPopularInfoRegister.setMostPopularInfoOfMoim(moim)
Expand Down

0 comments on commit b274155

Please sign in to comment.