First you must have a server instance installed and available see server instance. Sample here are based on using JQuery library.
Now you will be able to store/get/delete your json objects in an Apache DirectMemory instance.
Note the header X-DirectMemory-ExpiresIn to specify the ttl value in ms.
putObjectInCache=function(key,javascriptBean,expiresIn,serializer){ $.ajax({ url: 'cache/'+encodeURIComponent(key), data:JSON.stringify( javascriptBean ), cache: false, type: 'PUT', headers:{'X-DirectMemory-ExpiresIn':expiresIn,'X-DirectMemory-Serializer':serializer}, contentType: "text/plain", statusCode: { 204: function() { displayWarning("not put in cache"); }, 200:function( data, textStatus, jqXHR ) { var size = jqXHR.getResponseHeader('X-DirectMemory-SerializeSize'); displayInfo('put in cache with key:'+key+ " bytes stored:"+size); }, 500:function(data){ displayError("error put in cache"); } } }); }
$.ajax({ url: 'cache/'+encodeURIComponent(key), cache: false, type: 'GET', headers:{'X-DirectMemory-Serializer':$("#serializer" ).val()}, dataType: 'text', statusCode: { 204: function() { displayWarning("not found in cache"); }, 200:function( data ) { var wine = $.parseJSON(data); displayInfo('get from cache with key:'+key+",value:"+wine.description); }, 500:function(data){ displayError("error get from cache"); } } });
deleteFromCache=function(key){ $.ajax({ url: 'cache/'+encodeURIComponent(key), cache: false, type: 'DELETE', dataType: 'text', statusCode: { 204: function() { displayWarning("not found in cache"); }, 200:function( data ) { displayInfo(' key '+key+ ' deleted from cache'); }, 500:function(data){ displayError("error delete from cache"); } } }); }