pre-load the search cache

User 65339aced8

17-07-2004 22:13:20

Hi Szilard,


I use a frameset which includes a 'session' frame. It updates every minute. I want to pre-load the search cache with this frame as well. But found 2 problems. jsp:useBean of StructureCache is not possible, while the StructureCache constructor requires parameters.


Also I noticed with application.setAttribute the and loadIfNeeded, the cache was only once loaded within the 'session' frame(=OK). But again when the first search starts(=NOT OK).


Sincerely,


Niels.

ChemAxon 9c0afc9aaf

18-07-2004 08:25:37

Hi Niels,





Usually you do not need to use "jsp:useBean", and can program in the JSP just as in any other application.


Do you have some special reason for using it ?





I do not recommend dealing with StructureCache directly, it just adds unnecessary complexity to your code.


It's much simpler to call JChemSearch with an "impossible" query to load the cache. Since the fingerprints will filter out all of the structures, it has practically no overhead.


(fingerprint screening is blazing fast in memory)





An impossible structure may be something like "O1FBrClPS1ClClNcNn".





This method is also very useful because JChemSearch is able to run in a separate thread, so you can refresh the page while loading the cache.





(This prevents browser timeout when loading a big table into the cache.)

User 65339aced8

18-07-2004 09:04:38

Hi Szilard,


Thank you fro your always fast answers. I like the usebean for readibility. Not realy required though. I just tried your hint...and it works of course.


getResultCount required 1 hit.


Code:
<jsp:useBeanid="jchemcacheloader" scope="application" class="chemaxon.jchem.db.JChemSearch" />


<%


//Pre-load Structure Cache in application object


String preloadCacheMessage = "Cache Loading";


if (!jchemcacheloader.isRunning()) {


    if (jchemcacheloader.getResultCount()<1) {


        jchemcacheloader.setResultTableMode(chemaxon.jchem.db.JChemSearch.NO_RESULT_TABLE);


        jchemcacheloader.setFingerprintCaching(true);


        jchemcacheloader.setQueryStructure("c1cnccc1Cl");


        jchemcacheloader.setConnectionHandler(cpj.conh);


        jchemcacheloader.setStructureTable(cpj.structureTable);


        jchemcacheloader.setSearchType(chemaxon.jchem.db.JChemSearch.PERFECT);


        jchemcacheloader.setWaitingForResult(false);


        jchemcacheloader.run();


    } else {


        preloadCacheMessage = "Cache Loaded";


    }


}


out.println(preloadCacheMessage);


%>