Composite key entities returned from cache are corrupt / duplicated

Description

This issue also occurs for Enyim provider.

The issue is that when KeyAsString is called in these two providers, a composite-key entity returns it's default ToString, which is the class name typically. This is naturally not a unique key, and thus collisions occur.

Look at SysCache provider, and the key (as string) is formatted to include the GetHashCode of the key.

I will provide a patch in the github repo.

Environment

None

Activity

Show:

Frédéric Delaporte October 22, 2017 at 3:57 PM
Edited

Adding the hashcode is a crutch. An hashcode is never guaranteed unique, so you may still have collisions.

I think the only good fix is to override ToString on the key component class (or the whole entity class if its composite id is not a component).

Stuart Carnie March 29, 2011 at 3:06 PM

Fixed with unit tests on my github repo, specifically the following commit:

https://github.com/scarnie/nhcontrib/commit/650aedee0aa417f34097b145dfc75f8c3a746bec

External Issue

Details

Assignee

Reporter

Components

Priority

Who's Looking?

Open Who's Looking?
Created March 29, 2011 at 11:09 AM
Updated October 23, 2017 at 10:30 AM
Resolved October 23, 2017 at 10:30 AM
Who's Looking?