I have a play framework application which I have migrated to run on play framework 2.4.2. It is providing a RESTful API to a javascript/html frontend. Now I have some problems introducing caching.
LibraryController (transforming JSON/HTTP request to JSON/HTTP response):
public class LibraryController extends Controller {
public Result getBook(String isbn) {
Book book = LibraryManager.getBook(isbn);
BookDto bookDto = DtoMapper.book2BookDtos(book);
return ok(Json.toJson(bookDto));
}
}
LibraryManager (transforming domain model request to domain model response):
public class LibraryManager {
@Inject CacheApi cache;
public static Book getBook(String isbn) {
Book book = cache.get(isbn);
// ...
}
The problem I have here is that I get
non-static variable cache cannot be referenced from a static context
The way I am injecting the cache is as per Play 2.4.2 Cache API documentation. I didn't have this problem when I used caching as per the Play 2.2.x Cache API documentation. That version had a static method I could call.
What should I do? Should I make getBook non-static applying some singleton pattern? Or should I access the cache in some other way? Sample code would surely help out!
@deprecated Deprecated as of 2.6.0. Use {@link SyncCacheApi} or {@link AsyncCacheApi}
– Stigma