Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a caching layer on top of slick that could be applied globally?

Tags:

scala

slick

I am curios if using scala and slick, you could create a flexible caching layer (say using memcached) on top of slick.

Ruby has a cool library called IdentityCache: https://github.com/Shopify/identity_cache

It allows you to simply extend your model class (a trait in scala?) where you tell it to use this cache layer.

You can then tell it to only cache by Id, or cache associations also etc.

Sounds like a very cool thing, how could something like this fit into slick's design?

like image 406
loyalflow Avatar asked Mar 27 '14 16:03

loyalflow


People also ask

How caching is implemented?

The data in a cache is generally stored in fast access hardware such as RAM (Random-access memory) and may also be used in correlation with a software component. A cache's primary purpose is to increase data retrieval performance by reducing the need to access the underlying slower storage layer.

What is slick in Scala?

Slick is a Functional Relational Mapping library for Scala that allows us to query and access a database like other Scala collections. We can write database queries in Scala instead of SQL, thus providing typesafe queries.


1 Answers

I was thinking about how to add this to Slick lately, but we don't have any resources assigned to it for the foreseeable future.

You could build a query cache on top of Slick. Invalidating the cache based on the observed write operations on the base data can be very hard for arbitrary queries. You would need to restrict the supported operations for conditions in cached queries, e.g. to only use equality. Oracle and others have similar restrictions in place for their materialized view maintenance features.

like image 121
cvogt Avatar answered Oct 13 '22 01:10

cvogt