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.adapter.NActionListener;
 
public class ClientCache extends NApplication {
      @Override
      public void main(int argc, String[] argv) {
          final NFrame mainFrame=getMainFrame();
 
          final NImage closeImage = getClientCache().write("closeImg", 
                                       NImage.create("data:image/gif;base64,R0lGODlhCgAKAJEAAAAA"+
                                       "AP///1VVVf///yH5BAEAAAMALAAAAAAKAAoAAAIWhIYpZjl7IJLTU"+
                                       "AWae/k4eFHSxZFVAQA7"));
 
          new NButton(mainFrame,"Hello").addActionListener(new NActionListener() {
              @Override
              public void onAction(NEvent e) {
                    NFrame frame=new NFrame(mainFrame);
                    new NImageVIew(closeImage);
                    frame.setVisible(true);
              }
          });
 
          mainFrame.setTitle("Cache Example");
          mainFrame.setBounds(20,20,200,200);
          mainFrame.setVisible(true);
      }
}

1.2 Caching Data

import com.neurokernel.client.*;
import com.neurokernel.adapter.NActionListener;
 
public class ClientCache extends NApplication {
      @Override
      public void main(int argc, String[] argv) {
          final NFrame mainFrame=getMainFrame();
 
          String imageData="data:image/gif;base64,R0lGODlhCgAKAJEAAAAAAP///1VVVf///yH5BAEAAA"+
                                       "MALAAAAAAKAAoAAAIWhIYpZjl7IJLTUAWae/k4eFHSxZFVAQA7";
          final NImage closeImage = NImage.create(getClientCache().write("closeImg", imageData));
 
          new NButton(mainFrame,"Show").addActionListener(new NActionListener() {
              @Override
              public void onAction(NEvent e) {
                  NFrame frame=new NFrame(mainFrame);
                  new NImageVIew(closeImage);
                  frame.setVisible(true);
              }
          });
 
          mainFrame.setTitle("Cache Example");
          mainFrame.setBounds(20,20,200,200);
          mainFrame.setVisible(true);
      }
}

2. Application Cache

NeuroKernel client side applications can be cached to the browser for offline access. This may be particularly useful if the site to the application is down. Service workers are supported including fallback to AppCache mode. There may be client based limitations that could be solved in a later version. Please take note that, the site must have HTTPS certification for this to work.

3. Protocol Cache

Applications can cache their protocol in initial launch up until the main window is fully visible on the screen. This will increase the launch speed of the applications because protocol is already created for the main screen and stored. Protocol can be stored to persistent storage if available so that when the same application is executed again in a new session, system will pick its initial protocol from the persistent storage and immediately process it. Application startup protocol and initial protocol for each window can be cached to persistent storage as well. For remote applications, request to access to the data storage may be asked by the browser.