dinesh94 / simple-spring-memcached

Automatically exported from code.google.com/p/simple-spring-memcached
MIT License
0 stars 0 forks source link

SerializationType.CUSTOM problems #27

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago

This is a complementary issue to #25

> I don't think that we should modify behavior of Cacheable annotation because 
it's not a part of SSM but Spring. > If you want such feature you should 
request it from Spring team then SSM will support it out of the box.
> In raw SSM there is a workaround. You can use SerializationType.CUSTOM and 
register custom cache transcoder > using CacheFactory. In the transcoder you 
can define how to serialize and deserialize objects of given type.

I started to use SerializationType.CUSTOM but I have encountered some problems. 
But before I would like to summarise my use case: I had an inmemory entity map 
and want to use cache for complicated queries. But instead of persisting all 
entities in cache I would like to store only id's in map. Here is signature of 
one of my service method.

   List<VideoInfo> getWeeklyMostPopularVideosByCategoryId(Long categoryId, Boolean homePageAndSearchRestricted, Integer limit);

I would like to store List<Integer> in my cache instead of List<VideoInfo>. I 
am already using an inmemory store and this way I will reduce the serialization 
cost of my entities.

Here is the questions:

1. com.google.code.ssm.spring.SSMCache#put is calling null SerializationType. 
Is this expected? I was expecting to a resolving strategy for SerializationType.

2. My entities are in 3rd party clients. I can not modify them. (I also think 
that not polluting entities by library annotations such as Json annotation, JPA 
or Cache is a good practice.) Is there a way to register each entity by 
CacheFactory like this: 

CacheFactory.registerSerializationType(MyEntity.class,  
SerializationType.CUSTOM);

3. How can I provide custom serialization for Collection<MyEntity> types. What 
I would like to do is using provided serialization for Collection types but 
custom serialization for my entities.

Thanks

Original issue reported on code.google.com by cemalettin.koc@gmail.com on 3 Feb 2014 at 2:58

GoogleCodeExporter commented 9 years ago
1. Yes, it is. Because SSMCache is used when you use Cacheable Spring 
annotation and there is no way to pass information about serialization. If you 
use SSM annotations (ReadThroughMultiCache, ...) you can use 
com.google.code.ssm.api.format.Serialization to specify serialization type.
There is a workaround for Spring Cache annotations, to use Spring annotations 
and custom SSM serialization set CacheFactory.defaultSerializationType to 
SerializationType.CUSTOM.

2. No exactly because you have to specify default serialization type: CUSTOM, 
PROVIDER, JSON, ... and you can overwrite it at method level. It is not 
possible to define that objects of one class will be used JSON and another 
CUSTOM. 
You should look at:
om.google.code.ssm.transcoders.JsonTranscoder and 
com.google.code.ssm.mapper.JsonObjectMapper
it uses Jackson library for JSON serialization type. Using it you can define 
how given class will be serialized. You may also want to read more about 
Jackson's MixIn: http://wiki.fasterxml.com/JacksonMixInAnnotations, the library 
provide a lot of great features while serializing/deserializing java objects. 

3. If use use Spring Cacheable annotation then whole collection is stored under 
single key and you have to provide serialization for Collection. The 
com.google.code.ssm.mapper.JsonObjectMapper can again come in handy, it should 
use default (jackson) mechanizm for serializing collection/list and your custom 
for objects if dedicated JsonSerializer was registered.

Original comment by ragno...@gmail.com on 3 Feb 2014 at 10:11

GoogleCodeExporter commented 9 years ago
Do you need further assistance or everything is clear and I can close the issue?

BTW if you have some questions (not bug report or feature request) you may use 
mailing list: simple-spring-memecached@googlegroups.com

Original comment by ragno...@gmail.com on 6 Feb 2014 at 6:32

GoogleCodeExporter commented 9 years ago
I implemented a hybrid solution by using JsonTranscoder and JavaTranscoder. I 
will share details later. 

Thank you so much for your awesome support.

Original comment by cemalettin.koc@gmail.com on 6 Feb 2014 at 7:31

GoogleCodeExporter commented 9 years ago
This issue has been moved to github: 
https://github.com/ragnor/simple-spring-memcached/issues/27

Original comment by ragno...@gmail.com on 24 Feb 2014 at 5:50