私のコントローラの1つでは、同じ方法で最終的にレンダリングされる複数のURLがあります。例えば、この方法は、サーバが存在するネットワークをスキャンし、各接続機器の文字列表現をキャッシュし、各デバイスが特定のポートをリッスンし、次にレンダリングするために別の方法でその情報を送る:Playでのメモリ超過!フレームワークメソッドコール
アウトドアpublic static void networkScan(String networkTarget, String port)
{
//These two lists will never have more than 256 total entries
List<InetSocketAddress> listeningDevices;
Map<String, String> allDevices;
...Logic for discovering network devices...
//Store the results in a cache, for history preservation in the browser
Cache.set(session.getId() + "listeningDevices", listeningDevices);
Cache.set(session.getId() + "allDevices", allDevices);
showScan(listeningDevices, allDevices);
}
public static void showScan(List<InetSocketAddress> listeningDevices, Map<String, String> allDevices)
{
render(listeningDevices, allDevices);
}
public static void getCachedScan()
{
List<InetSocketAddress> listeningDevices = (List<InetSocketAddress>)Cache.get(session.getId() + "listeningDevices");
Map<String, String> allDevices = (Map<String, String>)Cache.get(session.getId() + "allDevices");
if(listeningDevices == null)
listeningDevices = new ArrayList<InetSocketAddress>();
if(allDevices == null)
allDevices = new TreeMap<String, String>();
renderScan(listeningDevices, allDevices);
}
をこのようにすれば、Playは無限のメモリをとる奇妙な配列のコピーを行います。 showScan()
の呼び出しを単にrender()
に変更し、名前がのビューを作成すると、すべて正常に動作し、メモリ不具合は発生しません。
さまざまなキャッシング設定に基づいて、showScanも使用するいくつかの方法があります。私は本質的にお互いのコピーであるたくさんのビューを望んでいないので、私は1つの対応するビューでただ1つのメソッドを実行しようとしています。
あなたの答えはうまくいくと思いますが、私は別の解決策をとることになりました。 '@ Util'インターセプタは、アクションメソッドを呼び出すときにリダイレクトイベントを防ぎます。これは、キャッシュを利用するかどうかに関係なく、すべての私の拠点をカバーします。それは十分に文書化されていませんが、私はGoogleグループについて質問したときに答えを得ました:http://groups.google.com/group/play-framework/browse_thread/thread/a44184382a370d52 – Indigenuity