Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Couchbase handle JArray support. #51

Merged
merged 1 commit into from
Mar 24, 2016
Merged

Couchbase handle JArray support. #51

merged 1 commit into from
Mar 24, 2016

Conversation

Kriskit
Copy link
Contributor

@Kriskit Kriskit commented Mar 24, 2016

I had an issue where I couldn't store arrays/collections straight into couchbase using the BucketCacheHandle resulting in an InvalidCastException when BaseCache uses GetCasted to return the expected type.

I've currently had to work around this by wrapping up all my cached items in another object so that the deserialisation happens as part of a child property deserialisation automatically when ToObject is called on a JObject value type.

I noticed that there are a couple of checks to see what type the cache item value was and determined that JValue and JObject both inherit from JToken, as does JArray. Since JToken has the ToObject method it seemed prudent to only check if the cache item value is an instance of JToken.

This should allow all JToken derived values to be used.

…lue as JToken rather than specifically checking for JObject and JValue as they both derive from JToken, also JArray was not supported - this should resolve that.
@MichaCo
Copy link
Owner

MichaCo commented Mar 24, 2016

@Kriskit thanks for the fix. Did you test it with a few different values, like simple string and a POCCO? I'm 50% sure I added those 2 checks explicitly instead of JToken for a reason. But I might be wrong ;)

@Kriskit
Copy link
Contributor Author

Kriskit commented Mar 24, 2016

@MichaCo I've tested it with a string, string[], int, int[], a single POCO and a collection of POCO's and seems to be working as expected.

I tested it using a console client in my codebase for testing our cache implementation which now wraps CacheManager.

Below is the output (note: I JSON stringify the POCO's in the output to see the values but they're definitely being deserialised from the cache properly).

Adding to cache:

Added value 'Hello World!' to cache using key 'String'.
Added value '["Test 1","Test 2","Test 3"]' to cache using key 'Strings'.
Added value '12345' to cache using key 'Int'.
Added value '[1,2,3,4,5,6,7]' to cache using key 'Ints'.
Added value '{"Name":"Test Item"}' to cache using key 'Item'.
Added value '[{"Name":"Test 1"},{"Name":"Test 2"},{"Name":"Test 3"}]' to cache using key 'Items'.

Retrieving:

Retrieved value 'Hello World!' from cache using key 'String'.
Retrieved value '["Test 1","Test 2","Test 3"]' from cache using key 'Strings'.
Retrieved value '12345' from cache using key 'Int'.
Retrieved value '[1,2,3,4,5,6,7]' from cache using key 'Ints'.
Retrieved value '{"Name":"Test Item"}' from cache using key 'Item'.
Retrieved value '[{"Name":"Test 1"},{"Name":"Test 2"},{"Name":"Test 3"}]' from cache using key 'Items'.

I hope this is satisfactory :)

One thing I'm a little confused about is, I tried to use the beta CacheManager NuGet feed to use the package that got generated from my pull request but it doesn't appear to have my change?? Did I miss something or is that not how it works? (don't actually use GitHub that much!) :)

@MichaCo MichaCo merged commit 6b48b9e into MichaCo:dev Mar 24, 2016
@MichaCo
Copy link
Owner

MichaCo commented Mar 24, 2016

ok sounds good /merged
The changes should be on myget in a few seconds I guess.

Thanks again! ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants