Guide to Caching
In order to ensure the high performance experience promised, NeuroKernel offers various client side in memory caching mechanisms. Caching is only done inside the task context and destroyed when the application exits.
1. Client Side Cache
Applications can cache all kinds of data to their task context for runtime use. One of the best way to utilize the client side cache is caching the images. In addition, Any control with dynamic graphics that implements IPixmapContext
system interface can also cache its content at any instance. Client cache accepts audio sound effects as well. Cached data is referenced by the system in a URI starting with n:cache/
pretext. If the value after the pretext is a number, corresponding system image will be used. The list of system images will be made available in this documentation after it is finalized.
1.1 Caching Images
import com.neurokernel.client.*; import com.neurokernel.client.adapter.IActionListener; public class ClientCache extends NApplication { @Override public void main(int argc, String[] argv) { NFrame mainFrame=getMainFrame(); NImage closeImage = getClientCache().write("closeImg", NImage.create("data:image/gif;base64,R0lGODlhCgAKAJEAAAAA"+ "AP///1VVVf///yH5BAEAAAMALAAAAAAKAAoAAAIWhIYpZjl7IJLTU"+ "AWae/k4eFHSxZFVAQA7")); new NButton(mainFrame,"Hello").addListener((IActionListener) e -> { NFrame frame=new NFrame(mainFrame); new NImageVIew(closeImage); frame.setVisible(true); }); setVisible("Cache Example"); } }
1.2 Caching Data
import com.neurokernel.client.*; import com.neurokernel.client.adapter.IActionListener; public class ClientCache extends NApplication { @Override public void main(int argc, String[] argv) { NFrame mainFrame=getMainFrame(); String imageData="data:image/gif;base64,R0lGODlhCgAKAJEAAAAAAP///1VVVf///yH5BAEAAA"+ "MALAAAAAAKAAoAAAIWhIYpZjl7IJLTUAWae/k4eFHSxZFVAQA7"; NImage closeImage = NImage.create(getClientCache().write("closeImg", imageData)); new NButton(mainFrame,"Show").addListener((IActionListener) e -> { NFrame frame=new NFrame(mainFrame); new NImageVIew(closeImage); frame.setVisible(true); }); setVisible("Cache Example"); } }