c4k
c4k

Reputation: 4436

How to delete cached element manually in Play Framework 2.3.X?

I have my web application using Play 2.3.3. Here is a method in my controller :

@Cached(key = "categories", duration = 3600)
public static Result index() throws ApiException {
    // Stuff read from database here
    return ok(MyView.render(data));
}

My question is how can I delete the categories element from the cache manually to force it to be regenerated ? For example, when I add a category in my database, I don't want to wait for the cache to expire to make it visible to my users.

I couldn't find anything in the documentation : https://playframework.com/documentation/2.3.x/JavaCache

So is the cache stored in RAM, somewhere in the filesystem ? Thanks.

EDIT : Ideally, I'd like to connect to my server, browse to a directory and delete the file. I suppose that's not possible with EHCache ?

Upvotes: 1

Views: 1077

Answers (1)

Michael Zajac
Michael Zajac

Reputation: 55569

You would use Cache.remove(key) from the docs you have linked.

 import play.api.cache.Cache

 Cache.remove("categories")

Play uses EhCache by default, which is an in-memory cache really only suited for single machine deployments. You can replace it another cache plugin though, play2 memcached for example.

Upvotes: 2

Related Questions