• Products
  • Solutions
  • Customers
  • Resources
  • Company
  • Pricing
  • Download
Try Playground
  • Client Side API Programming
  • Data Structures
  • Overview
Show / Hide Table of Contents
  • Programmer's Guide
  • Setting Up Development Environment
    • .NET
      • Client API Prerequisites
      • Server-side API Prerequisites
    • Java
      • Client API Prerequisites
      • Server-side API Prerequisites
    • Python
      • Client API Prerequisites
    • Node.js
      • 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
      • Cache Level Events
      • Item Level Events
      • Management Level Events
    • Pub/Sub Messaging
      • Overview
      • Topics
      • Publish Messages
      • Subscribe to a Topic
      • Pub/Sub Events
    • 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
    • Clear Cache
    • 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
    • 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 Structures Behavior and Usage in Cache

NCache supports the key-value pair structures where the key is a string type against a value that can be any primitive type, custom object, CacheItem, or a data structure. Groups, Tags, Expiration, Locking, Dependencies, and more can be assigned to these values.

Note

This feature is only available in the NCache Enterprise.

However, updating any value within a data structure, let's say a list, required fetching it from the cache, updating it, and then adding it back into the cache. This resulted in additional calls over the network. NCache has now eliminated this restriction by providing exclusive support for adding/updating data structures by manipulating data directly over the server. Hence, improving the overall performance.

NCache provides explicit support for the following data structures:

  1. List
  2. Queue
  3. HashSet
  4. Dictionary
  5. Counter

Apart from the functions provided by the native data structure interfaces, NCache extends its functionality by providing the option to specify metadata using a CacheItem. This means that the data structures can have Tags, Expiration, and Dependency, just like the other objects of the cache.

Important

The whole data structure will reside in one node of a clustered cache. For example, if you create a dictionary of 100 items, the whole dictionary of 100 items will exist in one node and not be distributed among other nodes.

The following figure shows the various data structures against their respective cache keys residing in a clustered cache of 3 nodes:

Data Structures in NCache

Feature Wise Behavior

Storage

  • Any item stored within a data structure is JSON-serialized to support native operations on the server, such as Contains.

  • The data structures have their own size along with the metadata which impacts the cache size.

PrimaryField Annotation

[PrimaryField] annotation can be used in user model classes for the data structures including the List and the Queue. The search operations on the data structures, such as Contains, can be used to serialize and send only that attribute/property instead of serializing and transferring the entire object over to the server. Only the PrimaryField attribute will be sent to the server and compared on the server side, decreasing the cost of the operation.

For example, the Customer class contains the property CustomerId, which is unique. This can be marked as the PrimaryField, and instead of comparing the complete object, for let's say Contains, comparing just the PrimaryField can complete the operation.

class Customer
{
    [PrimaryField]
    public string CustomerId { get;  set; }
    public string Name { get; set; }
    public string Address { get; set; }
}

Cache Keys

The data structures in NCache are named, i.e., they will be stored against a cache key like the other objects in NCache. If a cache key exists for a CacheItem, it cannot be used against a data structure.

Searchable Features

Searchable attributes like Groups, Tags, and Named Tags can be specified against a data structure during its creation. A CacheItem and a data structure can belong to the same group/tag/named tag. For more details, refer to Configure Searchable Attributes.

Data Invalidation Features

Eviction

The whole data structure is evicted from the cache if it falls under the "to be evicted" category. Not only does the data structure creation lead to the possible eviction, but any write operation on the data structure can trigger the eviction as well. For example, an item is added to the list such that the eviction criteria are met.

Expiration

The data structures can be invalidated from the cache after a specified interval of time, just like a CacheItem. The data structures support both, Absolute Expiration and Sliding Expiration.

Cache Dependencies [Deprecated]

The data structures support all the cache dependencies. For key-based dependencies, a list can be dependent on a CacheItem and vice versa. For more detail, refer to Configure Invalidation Attributes.

Querying on Data Structures

The data structures can be queried in the cache if they have searchable attributes configured. The searchable attributes include:

  1. Groups [Deprecated]
  2. Tags
  3. Named Tags

For more details, refer to Query on Data Structures.

Backing Source Providers

Read-Through

This is at the collection level only. The data structures can be read directly from a data source if not found in the cache. Individual items of a data structure will not be read from the data source. Therefore, the whole list of items should be fetched from the data source.

Write-Through

Write-through is triggered in two cases:

  1. Upon the data structure creation inside the cache (collection level).
  2. Upon the addition of data to an already existing data structure (item level).

Cache Loader and Refresher

You can load data structures into the cache on cache start-up automatically, using the Cache Startup Loader feature. This requires implementing an interface ICacheLoader with its methods. Also, if there is any change or update in the data, Cache Refresher is used to refresh the data. For more details, refer to Cache Loader and Refresher.

Client Cache

The data structure is not stored on the client cache. Any Get operation will fetch it from the main cache but not store it on the client cache. For more details, refer to Client Cache. For example, when we take a lock on a dictionary the whole dictionary gets locked, and no further operations.

Locking

The NCache provides an efficient locking mechanism for the data synchronization and the integrity within the cache store being updated by different parallel clients. NCache's internal locking guarantees the consistency of the data structures across the entire cache cluster for every update for the same data structure. For example, whole dictionary is locked when we lock a dictionary.

Event Notifications

The cache-level events and the key-based events are supported along with the data structure-level events and can be registered together on a data structure. For example:

  1. A list is created in the cache. This triggers the ItemAdded Cache Level Event and not the data structure event.

  2. An item is added to this list. This triggers the ItemUpdated Cache Level Event as the list has been updated and the ItemAdded data structure event as a new item has been added to the list.

Limitations

  • The nested data structures are not yet supported.
  • The CacheItem cannot be stored within a data structure. For example, a list of CacheItems is not yet supported.
  • The custom objects in the HashSet are not yet supported.
  • A Dictionary key can only be of string type.

Topology Wise Behavior

Mirror Topology

For Mirror Topology, operations are performed on the active node. These operations are then replicated to the passive node.

Replicated Topology

For Replicated Topology, the operations are performed on the node the client is connected to, which then replicates the operations to all nodes.

Partitioned Topology

In Partitioned Topology, the whole data structure exists on the same node. It is distributed based on the key. This means that no matter how large the dictionary is, it will exist on one node; the dictionary itself will not be partitioned across nodes.

Partition-Replica Topology

In Partition-Replica Topology, the operations behave the same as in partitioned topology. The data structure is distributed based on the cache key, and it will reside on the same node. Its replica will exist on the other node.

See Also

List Behavior and Usage in Cache
Queue Behavior and Usage in Cache
Set Behavior and Usage in Cache
Dictionary Behavior and Usage in Cache
Counter Behavior and Usage in Cache

In This Article
  • Feature Wise Behavior
    • Storage
    • PrimaryField Annotation
    • Cache Keys
    • Searchable Features
    • Data Invalidation Features
    • Querying on Data Structures
    • Backing Source Providers
    • Cache Loader and Refresher
    • Client Cache
    • Locking
    • Event Notifications
  • Limitations
  • Topology Wise Behavior
    • Mirror Topology
    • Replicated Topology
    • Partitioned Topology
    • Partition-Replica Topology
  • 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