4

I have a repository, which at the moment, reads from the database every time it is called. However, the data is only updated once a day, and to improve performance, I'd like the repository to store the data in memory.

When the data is updated, by another application (but same solution), I would like to notify the repository that it should reread the data in the database.

I considered writing a flag to a file, which the repository then reads every time, and rereads the database if true.

  • Is the application and repository run in same thread or as same process? – kayess Sep 15 '17 at 10:09
  • They are run in different processes. – Chris Wohlert Sep 15 '17 at 10:11
  • Do you know the exact time it updates or you just know it will happen at some stage of the day? – kuskmen Sep 15 '17 at 10:30
  • Is it guaranteed to only be updated once a day? Is it at a specific time? – Paul Sep 15 '17 at 10:30
  • I know the approximate time. Give or take 2 hours I think. – Chris Wohlert Sep 15 '17 at 10:45
1

What performance issues are you experiencing now ? Remember that you should not deal with these kind of problems before they really become a need.

Read a timestamp from another table. If the timestamp is updated, so is the data.

No need to introduce a flag in a file when you already have access to a database.

1

This is actually the same problem as how can a server inform a client that data has changed.

optimized polling:

For http optimisation both client and server have a last known modification date.

when httpclient asks for a http-url it also sends the client-side-last-known-mdoification-date of the url and the server replies either with "you already have the latest data" or with the new data.

assuming that repository-app and modifying-app have access to the same filesystem (i.e. are on the same machine) the modifying-app can set the lastModifiedDate of a known file and the repository app can check the lastModifiedDate of the known file before in-memory-copy is accessed.

I assume that interprocess comunication from server to all known repository-clients is overkill

0

For web applications/REST APIs, you can use cache-control headers to specify when you want data to be reread. There are even proxies you can put in front of your repository that will handle the caching for you. Basically, you would just have to make a GET request with a Cache-Control: no-cache header set after your data update happens.

  • I am not familiar with these, but it looks to me like the client tells the server when to reread. In this case, the most important thing is that the clients are agnostic to this. The application that knows when data is updated is run on the web server, but in a different process. – Chris Wohlert Sep 15 '17 at 11:22
  • The updater web server process can still make a request like a client after the update completes. – Karl Bielefeldt Sep 15 '17 at 17:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.