播放框架Ebean Bean缓存

时间:2014-01-27 16:40:12

标签: java playframework ebean playframework-2.2

在Ebean文档中,声明Ebean支持L2缓存,或者所谓的“Bean缓存”。

我有这堂课:

@CacheStrategy(readOnly = true)
@Entity
public class Currency extends Model {

    @Id
    private Long id;

    @Column(length = 5, nullable = false, unique = true)
    private String abbreviation;

    @Column(length = 20, nullable = false, unique = true)
    private String name;

    private static Finder<Long, Currency> find = new Finder<Long, Currency>(Long.class, Currency.class);

    public static Currency getDollar() {
        return find.where().eq("abbreviation", "USD").findUnique();
    }
} 

我在控制器中有这个代码:

Currency.getDollar();

Ebean.runCacheWarming(Currency.class);

Currency.getDollar();

但是当我查看Postgresql日志时,我可以看到即使在runCacheWarming之后,也会对数据库执行请求:

2014-01-27 17:34:07 CET LOG:  exécute <unnamed>: select t0.id as c0, t0.abbreviation as c1, t0.name as c2 from currency t0 where t0.abbreviation = $1 

2014-01-27 17:34:07 CET DETAIL:  paramètres : $1 = 'USD'

2014-01-27 17:34:07 CET LOG:  exécute <unnamed>: select t0.id as c0, t0.abbreviation as c1, t0.name as c2 from currency t0 where t0.abbreviation = $1

2014-01-27 17:34:07 CET DETAIL:  paramètres : $1 = 'USD'

我是否必须更改Play项目配置中的某些内容才能启用L2缓存?

0 个答案:

没有答案