caching strategies - Json in cache?

I’ve read all information on your site about how the Cache works.

However, there came up 2 questions.

Consider, I have some heavy query that takes 3500ms.
Wouldn’t it be great to store the result in the Cache? Of course, this is really no problem and extremely fast.

If I retrieve the result the “query” time comes down from 3500 to 50-100ms!
Nevertheless, I had to build a container class in order to store a List.

1st. Is it possible to have a functionality like getList(MyListItem.class) ?
Otherwise I’ll stick with the container method.

2nd.
If I understand your “Cache” right it seems like it uses something similar to Kryo.
So in order to get the result as JSON the server will:

  1. deserialize the bytes to Java Objects
  2. serialize the Java Objects to a JSON
  3. send it to the client.

If I’m wrong please correct me.
If not, wouldn’t it make sense to somehow put the client ready JSON into the cache to respond directly?
This might work if the customServerLogic was allowed to bypass/intercept the JSON serialization process.

regards,
Jens

3rd. If I’m allowed to put 50 Objects into the cache. What happens when I insert object 51? Will object 1 be deleted beforehand or will the insert just not happen?

1st. Is it possible to have a functionality like getList(MyListItem.class)

Why not store in cache List<MyListItem>? This way you get back exactly what you put in there.

wouldn't it make sense to somehow put the client ready JSON into the cache to respond directly?

You do not need to deserialize bytes to Java Objects. If you created a JSON representation of whatever object and put it into cache as a String. When you retrieve it back from cache, it will be string. Just turn it to JSON and return back to the client.

3rd. If I'm allowed to put 50 Objects into the cache. What happens when I insert object 51? Will object 1 be deleted beforehand or will the insert just not happen?

You will get an error. You can overcome this limitation, by purchasing a Function Pack that expands your Cache storage:
http://support.backendless.com/public/attachments/efe9be5ed3e7334c0704cc1a37d93d20.jpg&lt;/img&gt;

Why not store in cache List&lt;MyListItem&gt;? This way you get back exactly what you put in there.

This is not possible because the get() method expects a Class to deserialize.

I cannot pass List<MyObject> as parameter when asked for a class.

Technically you could pass List<MyObject> class as parameter, but it will not work for other reasons. The following however does work:

    BackendlessCollection&lt;Person&gt; personsCollection = Backendless.Data.of( Person.class ).find();
    List&lt;Person&gt; persons = personsCollection.getCurrentPage();


    // put the object into cache
    Backendless.Cache.put( "persons", persons );


    // now get it back
   Object[] personArray = Backendless.Cache.get( "persons", Object[].class );

When you put a collection into cache, it will come back as an array.

Are there cache object limitations on Backendless Standalone or does it depend just on ram?

There is a size limit on the object you can store. I will defer to someone from our team to provide the details.

Hi Jens!
In Backendless Standalone version there are no limits for quantity of cached objects.
It depends only from your local configuration.
But in both Backendless Standalone and in Backendless Online versions added limit for size of object in cache (information from doc): “…The size of the serialized object cannot exceed 10240 bytes”.

Regards,
Kate.