• Products
  • Solutions
  • Customers
  • Resources
  • Company
  • Pricing
  • Download
Try Playground
  • Client Side API Programming
  • Cache Keys and Data
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

Cache Keys and Data Caching Overview

NCache uses an enhanced key-value structure for storing objects and data caching. So, while conventional key-value stores contain a string key against a string value, NCache allows primitive data types, custom objects, NCache-specific objects (CacheItems), data structures, and JSON as values of each key. Therefore, each item added to the cache must have a unique string key.

Note

This feature is also available in NCache Professional.

Cache Keys in Data Caching

This key-value structure is advantageous for retrieving objects from the cache. While NCache supports multiple cache data retrieval methods - like querying and tagging - keys efficiently fetch the associated items without executing queries over the entire cache.

Keys in NCache have the following properties:

  • Unique - no duplicate keys are allowed
  • String-based only
  • Valid string - null/empty strings are not allowed
  • Case sensitive
Tip

Good practices for naming keys:

  • Provide meaningful names to your keys that describe the associated data. For example, you are likely to forget what "key1" is associated with compared to a key named Product:1001. This key name describes itself as a Product item with ProductID 1001.
  • For multiple classes, you can add a prefix before the key name to mark the key for the class. For instance, your data is such that Product and Customer objects can have "1001" as the key. These can be in the format [ClassName]_[KeyName] so that they are Product_1001 and Customer_1001 for clarification.
  • For key names with multiple words, you can use any character to make it readable, a few common ones being _ , & : - =. For example, Product_Item:1001.

Location Affinity between Items [Deprecated]

NCache provides a mechanism to store data in the cache that creates an affinity between items of different classes. You can store items of different types on the same node to save the matching cost while fetching items with similar keys. This mechanism maps similar entries at the back end, thus further speeding up data caching and retrieving.

Location affinity can be enabled manually while entering data into the cache. The item key must be the same inside braces {} as in the other item. For example, to create location affinity between Product and Order objects, you can specify key Product:1001 for a Product object in the cache and then create an affinity of the associated order by specifying Product:1001 within {}. So the Order object key can be specified as Order_{Product:1001}. This will ensure that the product and orders exist within the same node.

Supported Data in Data Caching

The objects stored in the cache for data caching can be:

Primitive data types

Note

This feature is also available in NCache Professional.

NCache supports the following primitive data types:

  • byte/sbyte
  • int/uint
  • short/ushort
  • long/ulong
  • char
  • float
  • double
  • decimal
  • bool

The non-primitive data types include:

  • object
  • string
  • DateTime
  • TimeSpan

Custom class objects

Note

This feature is also available in NCache Professional.

Data can also be any custom serializable class object, for example, Product class objects. The custom object data must be serializable, otherwise NCache will throw a Serialization exception.

NCache provides two ways of serializing custom objects:

  • Native Serialization: You can use the .NET provided [Serializable] attribute in your custom class.

  • Compact Serialization: NCache provides a custom serialization framework for custom objects. This framework provides cost-effective serialization for registered classes dynamically.

NCache's CacheItem objects

Note

This feature is also available in NCache Professional.

Data can also be encapsulated in NCache's CacheItem class. CacheItem allows you to add additional metadata along with the value being cached. This metadata defines the properties of the item like expiration, dependencies, and more.

You can read more about the properties of CacheItem here.

Data Structures

NCache now provides exclusive support for adding/updating data structures, where the data is manipulated directly over the server, improving performance. NCache provides support for the following data structures:

  • List
  • Queue
  • HashSet
  • Dictionary
  • Counter

Just like any data in NCache, these can be queried, locked, expired, and more. To learn more about using data structures in cache, refer to Data Structures in Cache.

JSON [Deprecated]

NCache also supports adding/modifying cache data in the form of JSON. JSON provides flexibility to data retrieval as custom objects can be retrieved as JSON and JSON objects can be retrieved as custom objects. The following are supported for JSON:

  • JsonObject
  • JsonArray
  • JsonValue
  • JsonNull

Similar to CacheItems, JSON data can be queried, locked, expired, and more. To learn more about using JSON in NCache, refer to Cache Data as JSON.

See Also

How to Connect to Cache
Add Data to Cache
Retrieve Existing Cache Data
Remove Data from Cache
Create Cache

In This Article
  • Cache Keys in Data Caching
    • Location Affinity between Items [Deprecated]
  • Supported Data in Data Caching
    • Primitive data types
    • Custom class objects
    • NCache's CacheItem objects
    • Data Structures
    • JSON [Deprecated]
  • 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