Add Guava Response Cache Spring Boot

To add simple response cacheing to a Spring Boot application.

 

  1. Add the guava dependency.
        <dependency>
          <groupId>com.google.guava</groupId>
          <artifactId>guava</artifactId>
          <version>18.0</version>
        </dependency>
    
  2. Configure the cache

    Annotate the config class

    import org.springframework.cache.annotation.EnableCaching;
    
    @EnableCaching
    

    Configure the bean

      /**
       * Response cache.
       */
      @Bean
      public CacheManager guavaCacheManager() {
        GuavaCacheManager guavaCacheManager = new GuavaCacheManager();
        guavaCacheManager.setCacheBuilder(CacheBuilder.newBuilder().expireAfterWrite(
            Long.parseLong(env.getProperty("request.cache.timeout", "600")), TimeUnit.SECONDS));
        return guavaCacheManager;
      }
    
    
  3. Annotate cacheable controller methods
    import org.springframework.cache.annotation.Cacheable;
    @Cacheable("mycache")
    
Advertisements

This week’s jam: Raspberry and apple

image

After successful micro-jamming of raspberry and then raspberry and blueberry. This week I’m trying raspberry and apple.

200g raspberries
120g grated bramley apple
300g jam sugar
Lemon juice.

I slowly heated all the ingredients and stirred regularly making sure not to rapidly boil as the apple needed to be cooked. This took around 12 minutes to cook the apples and have a good consistency.

This made two jars of jam. I’ll find out how good it tastes tomorrow.

TextMate Ruby error with Mac OS X Mavericks

Are you getting a TextMate error like this after upgrading your Mac to Mavericks

/Applications/TextMate.app/Contents/SharedSupport/Support/lib/ui.rb:129: warning: assigned but unused variable - pid
/Applications/TextMate.app/Contents/SharedSupport/Support/lib/progress.rb:57: warning: shadowing outer local variable - params
/Applications/TextMate.app/Contents/SharedSupport/Support/lib/progress.rb:55: warning: assigned but unused variable - ui_process
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require': /Applications/TextMate.app/Contents/SharedSupport/Support/lib/shelltokenize.rb:74: invalid multibyte escape: /[^\w_\-\+=\/\x7F-\xFF]/ (SyntaxError)
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /Applications/TextMate.app/Contents/SharedSupport/Bundles/Subversion.tmbundle/Support/svn_diff.rb:7:in `<top (required)>'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from -:3:in `<main>'

To fix. Simply downgrade the version of Ruby from 2.0 to 1.8. Both versions are installed. So it is as simple as changing a symbolic link.

Open Terminal which can be found in /Applications/Utilities then run the following commands:

cd /System/Library/Frameworks/Ruby.framework/Versions
sudo rm Current
sudo ln -s 1.8 Current

JQuery selectors and spaces in ids

I know that the general response to the question about using JQuery selectors for node ids that have spaces in them is to not have spaces in ids.  According to the HTML specification, spaces are not allowed.

ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens (“-“), underscores (“_”), colons (“:”), and periods (“.”).

As we live in a world where web browsers are lenient when it comes to standards, developers are inherently lazy, and you don't really want to rewrite too much of someone else's code just to add a simple feature.  You sometimes need to select nodes with ids that contain spaces.

The attribute selector is what you need.  e.g.

$('[id=An id with spaces]').click(function () {
    // Do something here
});

As a side note and something for me to remember.  The change() listener does not work all that well in Internet Explorer.  It's easier to use click()

#iwexpo Zingzam: Collate, enhance, and share knowledge

The online community platform Zingzam was launched yesterday at Internet World in London's Earl's Court exhibition centre.  

 

Come and see a demonstration and sign up for a 30 day — credit card free trial.  You can find Zingzam at E8150, just follow the pink.

 

I haver been a beta user of Zingzam for some time and the product offers a wide range of features.  From it's ability to brand your site in your own (garish) colours and logo with a few clicks of the mouse to the dashboard.   A major feature of the platform to see the current activity and health of your community.

 

Having RSS feeds of the content it is straight forward to user services such as twitterfeed or FeedBurner to syndicate content.

 

I look forward to using more of the features and continue to support the Zingzam community.