Steps to include lightweight cache in java applications – WhirlyCache

Posted by Martin Cabrera on May 28, 2009

Data caching is a very important consideration for JEE applications.

A classic problem for any application is to detect and solve the recurrent calls for optimizing the applications. Some cases can be:

  • database calls
  • business logic calls
  • remote method invocations

Data caching limits the number of remote invocations in distributed applications and improves performance of web applications by reducing the number of calls.

Several solutions exist to include a framework for implementing a cache.

Check out this interesting comparative table.

WhirlyCache (https://whirlycache.dev.java.net)

I use whirlycache in two projects and works really good. I recommend it to incorporate in a simple lightweight Web application
Whirlycache is a fast, configurable in-memory object cache for Java. It can be used, for example, to speed up a website or an application by caching objects that would otherwise have to be created by querying a database or by another expensive procedure. From the testing that we have done, it appears to be faster than any other Java cache that we have been able to inspect.

Steps to include WhirlyCache

(Step I) Donwload whirlycache and include it in your project -> https://whirlycache.dev.java.net/files/documents/1995/34601/whirlycache-1.0.1.zip

(Step II) Create a cache instance

CacheConfiguration cc = new CacheConfiguration();

cc.setName("KBCache");

cc.setBackend("com.whirlycott.cache.impl.ConcurrentHashMapImpl");

cc.setTunerSleepTime(60);

cc.setPolicy("com.whirlycott.cache.policy.LFUMaintenancePolicy");

cc.setMaxSize(10000);

Cache c = CacheManager.getInstance().createCache(cc);

(Step III) Use cache instance

c.store(key, object);
c.remove(key);
c.retrieve(key);

Example of java class (is a jboss seam entity class) – StockCache.java


[Post to Twitter] Tweet This Post 

Using Facebooker to make a Rails site with Facebook Connect (Part 3) 3

Posted by Augusto Guido on May 25, 2009

Welcome to part 3 of the facebooker trilogy

I’m kind of tyred of writing the same title over and over again and changing just the last number, problem is there are so many things we can do with this stuff we could write tons of this. I could put in the title what we will talk about specifically in this post, but the idea is to follow this post/tutorials in order. This will probably be the last part of this set of posts, the following ones will refer in it’s specifically to what will be done.

So far we explained how to configure facebooker, sign up, invite friends and bit of the theory. So today we’ll publish something in the users dashboard, so him and all his friends can see it his wall. So go to
developers.facebook.com/tools.php and select “Feed Template Console”, select the application you want and click next.

Give me a minute to explain you what we are doing.

We are going to register our feeds in facebook, and then we are going to call them by a number they will give us.
You can do this using facebooker, or you can register them in the link I gave you above. I think that using the facebook tools is way easier and also facebooker may be a bit out of date regarding this area due to all the legal and business changes in facebook. Also not event facebook has yet clear what they want: “At this time, the policy on automatically publishing one line stories has not been finalized”.

Anyway, complete the step guide for feeds in facebook and keep the number of the template you created. BTW while completing it you will find this kind of stuff “{*actor*}” without quotes. These are tokens that allow to put variable stuff (like names, links, etc.), you can read about them while creating the templates since they are well explained over there.

Now, you have the story. You need the users approval to publish it, so what facebook does is shows the story to the user and gives him otions to skip or publish. If we are in luck the users hits “publish”.

So we now obviously want to show it to the user so he can choose. Here’s the code

FB.ensureInit(function() {
var body_general = "Join them in my facebook connect site"
var template_data =
{
"actor":  "<%= @_logged_user.name %>",
"friends":"<%= @event.users.collect{|u| u.name_or_alias}.join(', ') %>",
"event":  "<%= @event.description %>",
"place":  "<%= @event.place %>",
"time" :  "<%= @event.start.strftime('%m/%d/%Y %I:%M %p') %>"
};
var user_message_prompt = "<%= @match.comment %>";
FB.Connect.showFeedDialog('the_number_of_your_template', template_data, [], body_general, null, FB.RequireConnect.require, FB.RequireConnect.promptConnect, user_message_prompt);
});

In the template data you have to complete the tokens you created when publishing your story. You can everything pretty well explained in this couple of links:

http://wiki.developers.facebook.com/index.php/JS_API_M_FB.Connect.ShowFeedDialog
http://wiki.developers.facebook.com/index.php/Feed.publishUserAction
http://wiki.developers.facebook.com/index.php/Publishing_Feed_Stories_to_Facebook

Pay attention to the “FB.ensureInit(function(){”, I don’t know why I couldn’t find anywhere in facebook that mention this should be there. If you don’t add this nothing will happen, maybe it’s obvios for some people, but it wasn’t for me. I’m sory I can’t remember where I find this, but you can read here what it does.

Well, that’s kind of the big picture of what you have to do to publish stories, remember this isn’t supposed to be a complete tutorial of everything you can do, just a guide based on my personal experience to get started.

Your facebook connect site should be quite complete now that you can signup, invite your friends and write stuff that will appear directly in facebook. Not to mention if you have used all the other resources facebook give us and facebooker facilitate us.

Thanks for reading!

[Post to Twitter] Tweet This Post 


Tweet This Post links powered by Tweet This v1.3.9, a WordPress plugin for Twitter.