With the rising demand for high-speed and scalable applications, distributed caching has become a crucial technique to enhance application responsiveness. However, when multiple clients perform read and write operations concurrently, the risk of the cache becoming inconsistent with the database increases. A common approach to mitigate this issue is using expiration mechanisms such as Time-to-Live (TTL) or Absolute Expiration, which remove cache entries after a defined period. While this method reduces the chances of serving outdated data, it is based on an estimation of how long the data remains valid, which can still lead to inconsistencies.

For datasets that are not frequently updated or have minimal impact, expiration-based caching may be sufficient. However, when the data is critical to business operations and outdated information can lead to financial or operational problems, it is essential to implement an efficient cache synchronization strategy.

Synchronizing NCache with Oracle Database

To ensure cache consistency with the database, NCache offers an advanced synchronization feature called Oracle Dependency. This feature utilizes Oracle Database Change Notification (DCN) to automatically remove cached entries when the corresponding data in the Oracle database is modified, ensuring the cache never serves stale data.

sync-ncache-oracle

Figure: Synchronize NCache with Oracle Server

Oracle Database Change Notification (DCN)

DCN is a feature within Oracle Database that notifies subscribed clients whenever specific data changes occur. When NCache is configured with OracleCacheDependency, it acts as an Oracle client to enable automatic synchronization between cache and database.

The process follows these steps:

  1. Oracle Database monitors changes in the subscribed data.
  2. A notification is sent to NCache upon data modification.
  3. NCache invalidates the corresponding cache entry.
  4. The next time an application requests the data, it retrieves an updated copy from the database.

Implementing Oracle Dependency in .NET 8 with NCache

NCache provides an Oracle Dependency API that allows applications to register cache items for automatic invalidation. When adding data to the cache, the following parameters must be provided:

Example: Synchronizing Cache with Oracle Database in .NET 8

Consider an online shopping platform built on .NET 8 where thousands of users browse products. On Christmas Day, a 40% discount is applied sitewide. If cached product prices do not reflect this update, customers might see incorrect pricing, leading to confusion and dissatisfaction. With NCache Oracle Dependency, cache synchronization ensures that the displayed prices remain accurate.

Auto-Reload Cache with ReadThru Provider

Instead of invalidating cache entries upon database updates, NCache ReadThru Provider allows automatic data reloading into the cache, ensuring fresh data availability without requiring the application to fetch it manually.

Implementation

Conclusion

Ensuring your application remains reliable and accurate is crucial, and outdated data can lead to significant business setbacks. With NCache’s Oracle Dependency, you can maintain synchronization between your cache and Oracle database, protecting your application from the risks of stale data. This solution helps safeguard your business and reputation, ensuring your cache consistently supports, rather than undermines, your application’s performance.