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.

Key Takeaways

Event-Driven Synchronization: NCache utilizes Oracle’s native Database Change Notification (DCN) to provide an active “Push” mechanism. This ensures the cache is updated the instant a database change is committed, eliminating the staleness risks associated with passive, time-based expiration (TTL).
Reduced Database Overhead: By eliminating the need for constant polling or redundant re-fetches, Oracle Dependency significantly lowers the CPU and I/O load on the database server. This allows the Oracle server to prioritize transaction processing over repetitive cache-refresh requests.
Granular Monitoring: The synchronization provider allows for precise control by monitoring specific SQL command text or Stored Procedures. This ensures that only the relevant cache items are invalidated or updated when their specific underlying data changes.
Proactive Data Availability: When paired with a Read-Through provider, NCache moves beyond simple cache invalidation. It automatically re-fetches and reloads fresh data into the cache immediately after a database change, ensuring the “hottest” data is always pre-loaded and ready for the next request.

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.

Feature Expiration (TTL/Absolute) Oracle Dependency (Sync)
Trigger Mechanism Time-Elapsed (Passive) Event-Driven (Active/Push)
Data Integrity Eventual/Stale-Prone Real-time / Synchronized
Resource Efficiency Higher (Redundant DB Reads) Lower (Notification Overhead)
Network Traffic Periodic Polling/Re-fetching On-demand Change Notifications
Distributed cache synchronization between NCache cluster and Oracle Database using Change Notification.

Synchronizing NCache with Oracle Server

Oracle Database Change Notification (DCN)

By leveraging Oracle’s native DCN, NCache eliminates the overhead of traditional polling-based synchronization, aligning with industry standards for high-performance database-to-cache integration. 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

By combining Oracle Dependency with a Read-Through provider, you transition from simple cache invalidation to proactive data management, ensuring that the ‘hottest’ data is always pre-loaded and ready for the next user request.

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.

Frequently Asked Questions (FAQ)

Q: What specific Oracle permissions are required for NCache synchronization?
A: To use OracleCacheDependency, the Oracle user account specified in your connection string must be granted the CHANGE NOTIFICATION privilege. This allows the NCache service to register a subscription with the Oracle server and listen for event-driven data modifications.

Q: How is the connection string structured for Oracle Dependency?
A: The connection string must define the User Id, Password, and Data Source. The Data Source should point to your specific Oracle server instance or TNS entry, ensuring NCache can act as a client to receive the Database Change Notifications (DCN).

Q: What occurs during the “Invalidate” stage of the synchronization process?
A: When the Oracle Database monitors a change in subscribed data, it sends a notification to NCache. NCache then immediately removes the specific stale entry from the cluster. This ensures that the next application request triggers a fresh data fetch rather than serving outdated information.

Q: How does the CommandText parameter function in a bulk operation?
A: When adding items to the cache using AddBulk, a unique OracleCacheDependency can be created for each item by specifying a unique SQL query in the CommandText. This allows NCache to track changes at the individual row level, ensuring that only the specific modified products are invalidated in the cache.