java - 是否可以查询 Hazelcast 缓存?如果是,该怎么做?
问题描述
我正在尝试使用 hazelcast 实现缓存。
这是我的代码。我的问题是,当 findAllGames() 执行时,我将所有游戏缓存在“gamesCache”中,而当 findGameByTypes() 执行时,我希望它查询“gamesCache”而不是访问数据库并返回结果。
@Cacheable(cacheNames = "gamesCache", key = "#root.methodName")
public List<Game> findAllGames() {
List<Game> games = gamesDao.getAllGames(); // dao call
//some database call
}
public List<Game> findGameByTypes(GameType gameType) {
List<Game> games = gamesDao.getGamesByType(gameType); // dao call
//some logic
}
public class Game implements Serializable {
private long gameId;
private String gameName;
private GameType gameType;
}
public class GameType implements Serializable {
private long gameId;
private String gameGenre;
private Boolean status;
}
findAllGames() 总是比 findGamesByTypes() 先命中。
现在缓存的地图是用“findAllGames”作为键和游戏列表作为值生成的。现在有没有办法使用 GameType 属性作为标准来查询地图。
有什么方法可以实现吗?我也愿意接受其他建议。
解决方案
您可以使用 Predicate 或 SqlQuery 查询 Hazelcast Map/Cache。在此处查看详细文档:https ://docs.hazelcast.org/docs/3.11/manual/html-single/index.html#distributed-query
推荐阅读
- java - spring boot 登录应用
- asciidoc - ASCII 文档中的域名
- apache-spark - 内存中缓存的数据帧大小如何影响 Apache Spark 中的处理时间?
- java - 将 ArrayList 添加到 Listbox Java
- python - 如何从 Python 调用 Postgres 11 存储过程
- express-validator - 如何在更新调用中使用快速验证器检查名称是否已存在
- android - 带有 proguard 的 Sigend APK 给出了 IncompatibleClassChangeError
- swift - Swift Struct:在运行时添加新参数
- ionic-framework - 在 ionic v4 应用程序中使用的最佳/更强的身份验证系统是什么?
- firebase - Firebase 规则中的验证