Can I load lots of data only once and use it on each request?

Posted by eikes on Stack Overflow See other posts from Stack Overflow or by eikes
Published on 2010-06-14T22:17:01Z Indexed on 2010/06/14 22:22 UTC
Read the original article Hit count: 101

Filed under:
|

Is there a way to load a big data object into the memory, which usually has to be loaded at each request, only once?

In Java you can instantiate an object in a servlet when this servlet is loaded, but once it's there you can use it in any request. Example is below. Can this be done in PHP?

public class SampleServlet extends HttpServlet {  
  private static HugeGraphObject hgo;

  public void init() {
    hgo = HugeGraphObjectFactory.get();
  }

  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String param = request.getParameter("q");
    response.getWriter().write(hgo.getSomeThing(param));
  }
}

© Stack Overflow or respective owner

Related posts about java

Related posts about php