I have a SQL procedure that I call often (around 10-25 times a second). The procedure itself is very well optimized, however, the pre-processing for this procedure requires a configuration based on the parameters (there are a few thousand configurations that are possible). This configuration is stored in the database as well and changes roughly once a day to once a month.
Currently I have it set up with a cache of configurations that I use to hold configurations that have recently been used (so I don't have to query the database for the configuration every time). The cache times out configurations after 30 minutes so if the configuration changes it will see it.
There are a couple problems with this:
1 - If the configuration changes it may take up to 30 minutes to see the change.
2 - If the configurations time out at different times on different running instances, the procedure will be run with different configurations at the same time.
So my question is: Is there any way to do this better? I don't want to query the database for the configuration every time but I also want to have the configuration updated as soon as it is changed.
One alternative I am considering is versioning the configuration in the database and checking the version from the database against the cache for every call. The problem with this is that it adds another query every time I call the procedure. I'm not sure what affect it will have on the load of the database.
Any suggestions are greatly appreciated