To decrease the amount of queries made to the database, SQLContainer uses internal caching for database contents. The caching is implemented with a size-limited LinkedHashMap containing a mapping from RowIds to RowItems. Typically developers do not need to modify caching options, although some fine-tuning can be done if required.

Cache usage with databases in multiuser applications always results in some kind of a compromise between the amount of queries we want to execute on the database and the amount of memory we want to use on caching the data; and most importantly, risking the cached data becoming stale.

SQLContainer provides an experimental remedy to this problem by implementing a simple cache flush notification mechanism. Due to its nature these notifications are disabled by default but can be easily enabled for a container instance by calling enableCacheFlushNotifications() at any time during the lifetime of the container.

The notification mechanism functions by storing a weak reference to all registered containers in a static list structure. To minimize the risk of memory leaks and to avoid unlimited growing of the reference list, dead weak references are collected to a reference queue and removed from the list every time a SQLContainer is added to the notification reference list or a container calls the notification method.

When a SQLContainer has its cache notifications set enabled, it will call the static notifyOfCacheFlush() method giving itself as a parameter. This method will compare the notifier-container to all the others present in the reference list. To fire a cache flush event, the target container must have the same type of QueryDelegate (either TableQuery or FreeformQuery) and the table name or query string must match with the container that fired the notification. If a match is found the refresh() method of the matching container is called, resulting in cache flushing in the target container.

Note: Standard Vaadin issues apply; even if the SQLContainer is refreshed on the server side, the changes will not be reflected to the UI until a server round-trip is performed, or unless a push mechanism is used.