Concepts
Filling the cache
Each of the non-abstract post-processors in Atoti Market Data are configured to use the cache. If these post-processors are part of your query, they will submit a request to fill the cache with market data during the prefetch phase. When they later run Get-by-key or List queries, these queries will use the cached data, improving retrieval speed.Cache Partitions
A fundamental aspect of the DirectQuery Local Cache design is the use of partitions. A cache does not contain the entire underlying table but instead holds only a subset, i.e., a partition. Partitions are configurable per cache. In the case of Atoti Market Data, a partition is defined as a unique combination ofAsOfDate, and MarketDataSet.
This means that when Atoti Market Data is used to retrieve a market data value, the cache with be filled with all market data values related to the AsOfDate
and MarketDataSet for the request.
Any subsequent requests for values with the same AsOfDate and MarketDataSet will be retrieved from the cache, making them significantly faster.
Set up
Cache descriptions
To cache data from a table, you must provide a cache description when the application starts. For each market data store there is a corresponding configuration class that exposes aSingleTableCacheDescription bean. These classes are available in the market-data-config module. These beans should be collected and used when configuring your Atoti application.
Each cache description is created with a cache capacity,
which determines the maximum number of rows or partitions to keep in the cache. You can configure the cache capacity by exposing a supplier bean for the relevant cache.
DatabaseCacheManager injection
Each of the non-abstract post-processors in Atoti Market Data is configured to use the cache but, to do so, they must be injected with the IDatabaseCacheManager. There is a configuration class inmarket-data-config that will inject the IDatabaseCacheManager into all relevant
post-processors. You can import this class in your project, and you must also expose IDatabaseCacheManager as a bean.
AllMarketDataDirectQueryConfig
Themarket-data-config includes an AllMarketDataDirectQueryConfig class that will import the cache descriptions for all stores, and the post-processor
injection configuration.
Advanced customization
If you are using the default Atoti Market Data stores and post-processors, simply follow the Set up steps to start caching market data. If you have made customizations or are not using all the components of Atoti Market Data you may need to make further changes.Cache partition customizations
A cache partition is defined as a combination ofAsOfDate and MarketDataSet for all Atoti Market Data stores. We believe this
provides the best level of granularity
for most projects.
If, however, you require a different partitioning, you must define your own cache definition for the table. Be sure not to also import the provided
cache config class.
AsOfDate and MarketDataSet from the location and use this to feed the cache.
If you change the partitioning, the post-processors will need to be updated. This is done by extending the post-processor and overriding the getConverter method.
Store customizations
The cache descriptions are configured based on the default structure of the underlying store. Most importantly, they require that the store has anAsOfDate, and a MarketDataSet field as these are used for the cache partitions.
If you have customized the store and these fields are no longer present, you must define your own cache definition for the table and update relevant post-processors.
This follows the same steps as to modify the cache partitioning.
New stores and post-processors
If you write new post-processors, you will need to ensure these are set up to work with the cache. If the new post-processor is retrieving market data from a custom store, you will need to provide your own cache description for the store.ADirectQueryCachingMarketDataPostProcessor is an abstract class that configures a DatabaseCachePrefetcher for you.
It uses getMarketDataRetrievalContainer().retriever().getTableName() as the name of the cache, and it assumes the cache partitioning uses
AsOfDate and MarketDataSet, pulling these levels from the first two entries in the AMarketDataPostProcessor.requiredLevels array.
ADirectQueryCachingMarketDataPostProcessor, for instance, you have a different cache partitioning,
you can instead implement the IDirectQueryCachingPostProcessor interface.
By implementing IDirectQueryCachingPostProcessor, your post-processor will be injected with the IDatabaseCache
(provided you import the injection configuration class) and there is a helper method to add the DatabaseCachePrefetcher.
However, you must specify the cache name and the converter.