BirdsCanada / NatureCountsAPI

NatureCountsAPI
0 stars 1 forks source link

Cached Data Renewal #8

Closed pmorrill closed 5 years ago

pmorrill commented 5 years ago

For efficiency, the api servlet is maintaining static collections of certain oft-used metadata. These maps are built on demand, and once built are currently never renewed (except if the application is restarted). The collections are:

We can build a renewal system in several ways, but the first question is how volatile will these data values be (in the database itself)? I expect they will be pretty static, so maybe just a timer that renews them on a pre-determined interval would work. Or I could track the time that they are built and use an expiry interval.

However, some input, please.

denislepage commented 5 years ago

Most of the metadata tables rarely change, if ever in some cases.

I can’t think of a reason right now to recycle the metadata on a schedule, though that could eventually apply to some tables (?).

That said, having a way to refresh the metadata without doing a server restart would be possibly handy. Assuming the data is stored in the same application context as the ROOT application managed from the web site, I can probably access the object and call a method on it if one is available. I have an admin page from which I can do this.

In other parts of the code, I cache these types of data in a Lookup subclass object, which is available from a specific ProjInfo, and I have a clearLookup method. Doesn’t have to be exactly the same for the API, but something similar.

pmorrill commented 5 years ago

That works. I will add a clearLookups function to the object. I may make it a static, since these are all static collections.

denislepage commented 5 years ago

Cool. And synchronized too.

pmorrill commented 5 years ago

I have added a static function in the api, to clear the static look-ups (collections). They will then be rebuilt on demand. The func is:

NatureCountsAPI#clearLookups() (public static void)

Will be part of the next deployment of master branch.

denislepage commented 5 years ago

Thanks,

I am adding some synchronized blocks around each clear() calls. The other uses seem to be correctly synced.

pmorrill commented 5 years ago

clearLookups in place