Don't use cache to store data because cache not remain all time you may get null values.
From Play Docs
It is important to understand that the cache contract is clear: when
you put data in a cache, you can’t expect that data to remain there
forever. In fact you shouldn’t. A cache is fast, but values expire,
and the cache generally exists only in memory (without persistent
backup)
From Similar Stack question
Play is stateless, you should not use the Cache as a data store. If
you are load balancing, there is no guarantee that you will return to
the same server. By keeping things in memory, you are breaking the
stateless nature of Play. The cache is best used when data already
exists in the database, but is being used to minimise frequent
database reads
Solution 1:Pass List to your view
In your controller
public static Result index() {
List<String> message= new ArrayList<String>();
message.add("message1");
message.add("message2");
message.add("message3");
return ok(index.render(message));
}
In your view
@(messages:List[String])
@main("index"){
@for(msg <- messages){
<div>@msg</div>
}
}
And you can always take help from sample projects provided by play which is in the zip file that you downloaded and extracted.
Note: You can pass variable from controller to your view in play by passing the
variable like you pass variable between functions in java.
Solution 2:Directly call the models function
In your view
@for(user<- User.all()){
<div>@user.getName</div>
}
where User is a model and all() is a function which returns list of users.
Solution 3:Use ajax call to get the list
See how to apply ajax in Play framework