Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support automatic eviction of caches after updating or deleting posts #9

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/main/java/run/halo/cache/page/CacheSentry.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package run.halo.cache.page;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
import run.halo.app.event.post.PostUpdatedEvent;

/**
* Sentry for evicting cache.
*/
@Slf4j
@Component
public class CacheSentry {

private final Cache cache;

public CacheSentry(CacheManager cacheManager) {
this.cache = cacheManager.getCache(PageCacheWebFilter.CACHE_NAME);
}

@EventListener
void onPostUpdated(PostUpdatedEvent event) {
cache.clear();
log.info("Received post updated event, and evicted page cache");
}

}