How to clear Apache Cayenne's cache?

In this post we refer to some simple ways - tricks in order to clear Apache Cayenne's cache. Clearing the cache is essential especially when huge datasets are extracted continuously from the database (and passed into objects).

A nice and easy solution for this is to create a new DataContext before executing queries that will fetch huge amounts of data. You just have to create a new object each time (before the query):

DataContext context = new DataContext.createDataContext();

and then use this for your query:

List queryRows = context.performQuery(selectQuery);

Another way, which is not always very effective but it can be used together with the previous one is to directly clear the data rows from the object store cache.

context.getObjectStore().getDataRowCache().clear();

In heavy duty applications you should always adjust the memory for the java heap using the runtime arguments -Xms128m (mininum memory size set to 128Mb) and -Xmx512m (maximum memory size set to 512 Mb). The values (128 and 512) are just an example (you should test your code and find out the right numbers for these values).

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <p>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.