Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8531739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:33:20+00:00 2026-06-11T09:33:20+00:00

I’m at the moment using spring AOP + Ehcache for our scala application. I

  • 0

I’m at the moment using spring AOP + Ehcache for our scala application. I really like the simplicity of using it with annotation but the not the part of using a big framework like spring to perform caching.

Do you know scala caching solution without being obliged to use a big framework like spring ?

Something like that without spring :

 @Cacheable(cacheName = "users")
 def getByUserName(userName: String): User = {
   val userEntityFound = dao.findOne(dao.createQuery.field("email").equal(userName))
   userEntityMapper mapToDomainObject userEntityFound
  }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T09:33:22+00:00Added an answer on June 11, 2026 at 9:33 am

    I think you’ll have to differentiate between the caching library and the API to access it. The caching libraries I have seen been used in a Scala environment are the same than the ones used in Java land. For (potentially) distributed caching something like Ehcache or memcached is used. For local caching the cache utilities of the guava library are commonly used.

    It is quite easy to write a wrapper to the native cache APIs in order to have a more scala idiomatic way to access the cache. Annotations as you have used them in your example is a common way to access library abstractions in Java but it is not that common in the Scala world. The play! framework for example has a cache abstraction which is, by default, bound to Ehcache. It allows constructs like:

    val user: User = Cache.getOrElseAs[User]("item.key") {
      User.findById(connectedUser)
    } 
    

    Twitter had a wrapper for the guava cache in their scala utils but removed them. I think that is the case because in current guava versions it is very simple / pragmatic to access it directly.

    val cache = 
     CacheBuilder.newBuilder().
      maximumSize(1000).
       build((key:String) => q(key)) 
    

    This for example will work fine if you have the following implicit conversion in scope:

    implicit def functionToCacheLoader[F, T](f: F => T) = {
     new CacheLoader[F, T] {
      def load(key: F) = f(key)
     }
    }
    

    Finally it is also quite easy to add some sugar to the guava cache itself:

    implicit def pimpCache[F, T](cache: Cache[F, T]) = {
     new PimpedCache(cache)
    }
    
    class PimpedCache[F, T](cache: Cache[F, T]) {
     def getOption(key: F) = {
      val value = cache.getIfPresent(key)
      if(value == null) None else Some(value)
     }    
    }
    

    Those are the main abstractions for caching I use. Here is a link to a gist with all the code I need. I also have a plugin for the play! Cache abstraction which uses guava under the hood which I can share if you have the need to use it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.