• Products
  • Solutions
  • Customers
  • Resources
  • Company
  • Pricing
  • Download
Try Playground
  • Client Side API Programming
  • Expirations
  • Overview
Show / Hide Table of Contents
  • Programmer's Guide
  • Setting Up Development Environment
    • .NET
      • Client Development Environment
      • Client API Prerequisites
      • Server-side API Prerequisites
    • Java
      • Client Development Environment
      • Client API Prerequisites
    • Python
      • Client Development Environment
      • Client API Prerequisites
    • Node.js
      • Client Development Environment
      • Client API Prerequisites
  • Client Side API Programming
    • Error Handling
    • Troubleshooting
    • Cache Keys and Data
    • How to Connect to Cache
    • Basic Operations - An Overview
      • Add Data
      • Update/Insert Data
      • Retrieve Data
      • Remove Data
    • Groups
      • Overview
      • Add/Update Data with Groups
      • Retrieve Data with Groups
      • Remove Data with Group
      • Search Group Data Using SQL
      • Delete Group Data Using SQL
    • Tags
      • Overview
      • Add/Update Data with Tags
      • Retrieve Data with Tags
      • Remove Data with Tags
      • Search Tag Data Using SQL
      • Delete Tag Data Using SQL
    • Named Tags
      • Overview
      • Add/Update Data with Named Tags
      • Remove Data with Named Tags
      • Search Data with Named Tags Using SQL
      • Delete Data with Named Tags Using SQL
    • Expirations
      • Overview
      • Absolute Expiration
      • Sliding Expiration
    • Data Dependency
      • Key Dependency
      • Multi-Cache Dependency
    • Dependency on Database
      • SQL Server
      • Oracle
      • OleDB with Polling
      • CLR Procedures in SQL Server
    • Dependency on External Source
      • File Dependency
      • Custom Dependency
      • Aggregate Dependency
    • Locks
      • Types of Locking
      • Pessimistic Locking
      • Optimistic Locking
    • SQL Query
      • Overview
      • Define Indexes Programmatically
      • Query with ExecuteReader and ExecuteScalar
      • Delete Data with ExecuteNonQuery
      • SQL Reference
    • LINQ Query
      • Overview
      • LINQ Query for Objects
      • LINQ Reference
    • Data Structures
      • Overview
      • List
      • Queue
      • Set
      • Dictionary
      • Counter
      • Invalidation Attributes
      • Searchable Attributes
      • Query on Data Structures
      • Remove from Data Structure
    • Events
      • Overview
      • Cache Level Events
      • Item Level Events
      • Management Level Events
    • Pub/Sub Messaging
      • Overview
      • Topics
      • Publish Messages
      • Subscribe to a Topic
      • Pub/Sub Events
      • Monitoring Topic Statistics
    • Continuous Query
      • Overview
      • Use Continuous Query
    • Stream Processing
      • Add/Update Stream Data
      • Retrieve Stream Data
    • JSON
      • Overview
      • Use JSON Objects
      • Query JSON Data
    • Security API
      • Login with Credentials
    • Management API
    • Error Logging
    • Location Affinity
  • Server-side API Programming
    • Loader and Refresher
      • Overview
      • Implement Loader and Refresher
      • Components of Loader/Refresher
    • Data Source Providers
      • Read-through
        • Implement Read-through
        • Use Read-through
      • Write-through
        • Implement Write-through
        • Use Write-through
        • Use Write-behind
        • Monitor Write-through Counters
    • Custom Dependency
      • Implement Extensible Dependency
      • Implement Bulk Extensible Dependency
      • Implement Notify Extensible Dependency
    • Bridge Conflict Resolver
    • Entry Processor
      • Overview
      • Implement Entry Processor
    • MapReduce
      • Overview
      • Implement MapReduce
      • Use MapReduce
    • MapReduce Aggregator
      • Overview
      • Implement and Use Aggregator
    • Compact Serialization
  • Client Side Features
    • ASP.NET Core Caching
      • Session Storage
        • Session Provider
        • IDistributedCache
        • Sessions Usage
        • Multi-site Session Provider
        • Session Sharing with ASP.NET
      • SignalR
        • NCache Extension for SignalR Core
      • Response Caching
        • Configure and Use
        • Configure with IDistributedCache
      • Data Caching
        • NCache API
        • IDistributedCache API
      • Data Protection Provider
        • Configure
    • Java Web App Caching
      • Web Sessions
        • Overview
        • Configure App
          • Add Maven Dependencies
          • Deploy Application
        • Multi-site Sessions
    • Node.js App Caching
      • Web Sessions
    • ASP.NET Caching Benefits and Overview
      • ASP.NET Session State Provider Properties
      • Multi-region ASP.NET Session State Provider Configuration
      • Session Sharing between ASP.NET and ASP.NET Core
      • ASP.NET SignalR Backplane
        • NCache Extension for SignalR
      • ASP.NET View State Caching
        • View State Content Optimization Configuration
        • Group View State with Sessions
        • Limit View State Caching
        • Page Level Grouping
      • ASP.NET Output Cache
        • Output Caching Provider Overview
        • Output Cache with Custom Hooks
  • .NET Third Party Integrations
    • Entity Framework (EF) Core
      • Installation
      • Configure
      • EF Core Extension Methods
        • Extension Methods
        • Cache Handle
        • Caching Options
        • Query Deferred API
      • Logging in EF Core
    • Entity Framework EF 6
      • EF Second Level Cache
      • EF Caching Resync Provider
      • EF Caching Configuration File
    • NHibernate
      • Second Level Cache
      • Query Caching
      • Synchronize Database with Cache
    • Debug NCache Providers in Visual Studio
  • Java Third Party Integrations
    • Hibernate
      • Second Level Cache
      • Configure Cacheable Objects and Regions
      • Configure Application
      • Query Caching
    • Spring
      • Overview
      • Use NCache with Spring
        • Configure Generic Provider
        • Configure JCache Spring Caching Provider
        • Configure Caching Declaration
        • Configure Spring Sessions
    • JCache API
      • CRUD Operations
      • Expiration
      • Events
  • Third-Party Wrappers
    • AppFabric to NCache Migration
      • AppFabric API vs. NCache API
      • Configuration Differences Between AppFabric and NCache
      • Migrating from an AppFabric Application to NCache
    • Redis to NCache Migration
      • Redis to NCache Migration
    • Memcached Wrapper
      • Memcached Gateway Approach
      • Memcached Client Plugin for .NET

Data Expiration Types and Strategies: Overview

NCache provides support for time-based data invalidation, allowing you to set a specific time or interval for cache data to expire. This method of invalidation is particularly useful in scenarios where the frequency of data changes can be determined. For instance, region data may not change frequently, making time-based expiration an ideal approach to invalidate such data.

Furthermore, expiring outdated data from the cache ensures that the client receives relevant and up-to-date information. For example, the units available for a certain product may be changed in the database, but not updated in the cache. Hence, expiring such data from the cache after a certain period will result in fresh data loaded into the cache on the next client request.

Another application of data expiration is session management. If a session remains inactive for a specified duration, it can be removed from the cache due to its idle state.

An expiration value is added to the cache items. NCache maintains an index for items with time-based expiration. A dedicated thread checks cache data for these expired items periodically after a configurable interval of time called Clean Interval. By default, its value is 15 seconds, which means that the maximum time an item can take to be removed from the cache is (expiration time + clean interval + time taken by cleanup activity). Hence, you should select this interval carefully according to the expiration time of your data.

Absolute Expiration

You can add an item to the cache with Absolute Expiration by specifying the exact date and time at which the item should be invalidated. When this time elapses, the item will be removed from the cache. Here, NCache maintains UTC time for Absolute Expiration on the caching servers which facilitates the case where clients and cache servers are in different time zones. This means that the expiration time specified by clients (in any time zone) will be converted to UTC on the cache server and the item will expire on the exact date and time as specified by clients. You can specify the expiration time ranging from seconds to days and months.

Note

This feature is also available in NCache Professional.

However, note that the item will be removed when expired on the next cache Clean-up Interval. For example, if you specify an expiration of 10 seconds with an item and cache Clean-up Interval is configured to 15 seconds, then the item will be removed within the time frame of 15-25 seconds.

Sliding Expiration

In this expiration, you want the cache to retain the data as long as it is being used by the application and remove any data that has not been used for a specific period of time. Every time the user accesses the cache data with Sliding Expiration, its cache life will extend by the specific expiration interval, e.g., an item with 30 seconds Sliding Expiration will be removed from the cache if the user will not access it for at least 30 seconds. However, with each access, the item's expiration interval will reset to 30 seconds, extending its life in the cache by 30 seconds.

Note

This feature is also available in NCache Professional.

For example, session data can be stored in the cache as long as the session is active. For this type of data, you can specify Sliding Expiration, let's say 15 minutes. Hence, if activity occurs within the specified time interval, the session's expiration interval will be reset to 15 minutes in the cache.

Similar to Absolute Expiration, cache items with Sliding Expiration are removed on the cache Clean-up Interval.

Warning

If no expiration is provided with the cache item, it will reside in the cache till explicit removal. This can overwhelm the cache storage.

Also please refer to Eviction Policies which is another feature of NCache to control cache storage usage.

Default Expirations

NCache also supports default expirations that can aid you in setting your data invalidation strategies with more flexibility. Default expirations are configured via the NCache Management Center or config.ncconf, so there is no need to change the code if you want to change the expiration value which is passed via API. Moreover, if the same application requires multiple expiration values, default expirations can be used.

NCache provides the following default expirations:

  1. Default Absolute
  2. Default Sliding
  3. Default Absolute Longer
  4. Default Sliding Longer

All of the default expirations have a minimum value of 5 seconds.

Let's suppose Default Absolute is configured with 5 seconds and Default Sliding Longer expiration is configured with 10 seconds. An object of the Product class is added to the cache with Default Absolute and a session is added with Default Sliding Longer expiration. Once the object is added, you want to change the expiration value for both to 15 seconds. Instead of reinserting the objects with the new expiration values, you can simply change the configuration from the NCache Management Center or config.ncconf, without any code change.

There are multiple scenarios where the configuration of expiration policy through the NCache Management Center and API will overlap, and will trigger the following behaviors. Note that non-default expiration refers to Absolute and Sliding expiration.

Default Expiration Expiration in API Call Behavior
Configured Default expiration Default expiration
Configured Non-default expiration Non-default expiration
Configured None Default expiration
Not Configured Default expiration No expiration
Not Configured Non-default expiration Non-default expiration
Not Configured None No expiration
Important

For CacheItem, the default value of Absolute and Sliding Expiration is "NoAbsoluteExpiration" and "NoSlidingExpiration". Hence, if Default Expiration is configured but no expiration is configured in API with CacheItem, No expiration will take place as its Default Expiration value overwrites the configured Default Expiration.

Expiration in Clustered Environment

In a clustered cache environment where multiple caching servers are involved, expiration is handled differently in various NCache topologies.

  • In the Mirrored topology, the active node will perform expiration and synchronize it on the passive node.
  • In the Replicated cache, expiration is performed by the coordinator node and the operation will then be synchronized to the other clustered nodes.
  • In the Partitioned topology, as data is distributed on separate nodes, each node is responsible for its own item expiration.
  • For Partition-Replica topology, expiration will be performed on active nodes and propagate to their respective replicas.
  • Client cache will utilize the same expiration enabled on the clustered cache. However, the Sliding expiration is added as Absolute expiration once it is synchronized with the cache, as it causes inconsistency if the value slides in the clustered cache but not in the client cache.

See Also

Absolute Data Expiration in Cache
Sliding Expiration
Eviction

In This Article
  • Absolute Expiration
  • Sliding Expiration
  • Default Expirations
  • Expiration in Clustered Environment
  • See Also

Contact Us

PHONE

+1 (214) 764-6933   (US)

+44 20 7993 8327   (UK)

 
EMAIL

sales@alachisoft.com

support@alachisoft.com

NCache
  • NCache Enterprise
  • NCache Professional
  • Edition Comparison
  • NCache Architecture
  • Benchmarks
Download
Pricing
Try Playground

Deployments
  • Cloud (SaaS & Software)
  • On-Premises
  • Kubernetes
  • Docker
Technical Use Cases
  • ASP.NET Sessions
  • ASP.NET Core Sessions
  • Pub/Sub Messaging
  • Real-Time ASP.NET SignalR
  • Internet of Things (IoT)
  • NoSQL Database
  • Stream Processing
  • Microservices
Resources
  • Magazine Articles
  • Third-Party Articles
  • Articles
  • Videos
  • Whitepapers
  • Shows
  • Talks
  • Blogs
  • Docs
Customer Case Studies
  • Testimonials
  • Customers
Support
  • Schedule a Demo
  • Forum (Google Groups)
  • Tips
Company
  • Leadership
  • Partners
  • News
  • Events
  • Careers
Contact Us

  • EnglishChinese (Simplified)FrenchGermanItalianJapaneseKoreanPortugueseSpanish

  • Contact Us
  •  
  • Sitemap
  •  
  • Terms of Use
  •  
  • Privacy Policy
© Copyright Alachisoft 2002 - 2025. All rights reserved. NCache is a registered trademark of Diyatech Corp.
Back to top