Built-in Card Cache
- 3 minutes to read
The Bootstrap Card View control has a built-in cache that stores visible card data and allows the control to avoid additional data binding.
Card Cache Life Cycle
Bootstrap Card View copies field values of visible and invisible columns to an internal data collection contained in a hidden field. A page sends the hidden field values to the server with postback and callback data. On the server, this data is deserialized.
When Bootstrap Card View requires card data, the control attempts to load that data from the card cache. If all required data is available in the cache, Bootstrap Card View does not send a query to the database. Since the card cache contains only visible card data, this mechanism is effective exclusively if a card list on the current page does not change. For example, the card cache is particularly useful in the following scenarios when:
- A user selects or focuses a card.
- Another page control initiates a page request. In this case, Bootstrap Card View data does not change unless Bootstrap Card View is modified on the server side during this request.
Sort, filter, and page operations cause new cards to appear on a page. Card cache does not have data for new cards and Bootstrap Card View sends a query to the database to obtain necessary data.
Methods That Can Force Data Binding
- GetCardValues(Int32, String[]) |
Find...TemplateControl
- These methods return card values. When you call these methods, Bootstrap Card View searches for a value in the card cache. If the required card data is found, data binding does not occur. Bootstrap Card View binds to a data source if the card cache is disabled or has no required data.
- GetRow(Int32) | GetDataRow(Int32)
- These methods return a card data object rather than card values. Bootstrap Card View does not store data objects in the row cache, therefore, these methods cause data binding even if the card cache contains required data.
Disable Row Cache
Set the EnableCardsCache property to false
to disable the card cache. This option can be useful in the following cases:
- Bootstrap Card View displays real-time data.
- Bootstrap Card View is bound to data created at runtime. The control always reloads data from the server when you call the DataBind() method.
- Bootstrap Card View contains CardViewBinaryImageColumn. Since caching a binary image may take long, you can disable the card cache to speed up page loading.
How to Store Complex Objects in Cache
If you bind Bootstrap Card View to an XPO or custom objects that use a referenced association, the control also tries to cache references. The caching operation is similar to the ToString
method. Serialization of a custom object copies data row values from a data source into an internal data collection. However, object deserialization (restoration from string to object) raises an exception:
"TypeConverter cannot convert from System.String"
You can resolve the issue in the following ways:
- Disable the card cache.
- Implement a custom TypeConverter derived class that can convert objects from the String type correctly. This approach is demonstrated in the following GitHub example: How to implement a custom TypeConverter class for an XPO object