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:
deserialize the bytes to Java Objects
serialize the Java Objects to a JSON
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.
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?
Technically you could pass List<MyObject> class as parameter, but it will not work for other reasons. The following however does work:
BackendlessCollection<Person> personsCollection = Backendless.Data.of( Person.class ).find();
List<Person> 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.
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”.