【发布时间】:2018-11-19 06:34:07
【问题描述】:
我正在尝试使用 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 属性作为条件来查询地图。
有什么方法可以实现吗?我也愿意接受其他建议。
【问题讨论】:
标签: java spring caching hazelcast hazelcast-imap