Purpose of Custom cache mule - caching

Mule got inbuild object stores to cache data, But what is the purpose of using custom object stores under caching strategies? If possible, Please mention a usecase.

Custom object stores are useful when you want to use a custom persistence mechanism for your ObjectStore's
By default Mule provides two implementations, in-memory and a file based persistent store.
One possible use-case is, if you use Enterprise Edition have clustering enabled, you also have the ability to share these stores across multiple Mule nodes. However if you do not use EE or clustering but still want to share data between multiple Mule's, then you will need to use a persistent object store that can be shared across multiple mule nodes.
The ObjectStore interface has many implementations so you can choose a persistence mechanism that best suits you. Examples include Redis, Ehcache, Mongo, Cassandra, JDBC. More on this here:http://java.dzone.com/articles/synchronizing-data-across-mule

Ryan has given the correct explanation.. I just want to add:-
Mule uses object stores whenever it needs data to persist for later retrieval.
Custom Object store can be configure using Java classes and you can customize the Object store as per your need..
You can customize it and control your Cache and the Cache Keys, as well as store and retrieve the data, log you Cache keys and Cache contents, list you Cache keys etc from the Java class and that means full control on the Custom Object store ..
Please go through the following links :-
http://ricston.com/blog/cache-scope-ehcache/
http://java.dzone.com/articles/cache-scope-ehcache
http://www.mulesoft.org/documentation/display/current/Mule+Object+Stores

Related

Spring boot jpa entity table name from property file

We are working on a spring boot library to generate and validate OTP. It uses database to store the OTP.
We are using Spring Data JPA for Database operations, as it will be easy to handle multiple database systems according to the project.
Now we have ran in to a problem, most of our projects uses Oracle with a single database.
When using the the same lib in multiple projects there is a name conflict.
So we want the name of the OTP table to be configurable using a property file.
We tried #Table(name = "${otp-table-name}") But its not working.
We did a lots of research and found out the hibernate naming strategy configuration can help.
But we dont want to use lots of configuration in our library as we need the library to be easily usable in the projects.
Can someone help us on this aspect.
Thanks in advance.
You can dynamically determine the actual DataSource based on the current context, use Spring's AbstractRoutingDataSource class. You could write your own version of this class and configure it to use a different data source based on the property file.
This allows you to switch between databases or schema without having to change the code in your library.
See: https://www.baeldung.com/spring-abstract-routing-data-source
Using a NamingStrategy is good approach.
You could let it delegate to an existing NamingStrategy and add a prefix.
Use a library specific default for the prefix, but also allow users of your library specify an alternative prefix.
This way your library can be used without extra configuration, but can also handle the case of multiple applications using it in the same database schema.
Of course this might involve the risk of someone using the default prefix without realizing that, that is already used.
It is not clear what the consequences of that scenario are.
If the consequences are really bad you should drop the default value and require that a project specific prefix is used.
When no prefix is specified throw an exception with an instructional error message telling the user, i.e. the developer how to pick a prefix and where to put it.

How does multi-tenancy work in infinispan

How does multi-tenancy work?
Multi-tenancy is achieved by namespacing. A single Infinispan cluster can have several named caches (attached to the same CacheManager), and different named caches can have duplicate keys. So this is, in effect, multi-tenancy for your key/value store.
source
does anyone have an idea/example on how to configure a cache to be multitenant?
I have already read the documentation but I didn't find an example to follow.
ps: I am using infinispan in embedded mode
thank you
There is no configuration in Infinispan for multi-tenancy. The sentence explains how to achieve it: you use the cache name to distinguish the namespace.
For example, for a specific group of users, you can create caches with the name "group_a_<cache_name>". In addition, you can set up authentication (documentation)

Using Redis with Laravel: Do I use the Cache driver, or the Redis class?

I was looking at the Laravel docs and I see a cache driver and a redis class. Looking at the cache class it seems like I could just use this to store things in Redis as I just change which driver I am using for caching to the already added Redis driver. However there is also a separate Redis class. Why is there a separate redis class? If the cache class can do the same thing and allow me to also swap which driver I use if ever needed, what reason is there to use the Redis class?
Maybe I am missing something here but I am just confused which one I want to use to store key's and data in redis? I am using Laravel 5.
From the documentation, the Cache class (Facade):
provides a unified API for various caching systems.
One of which is Redis. Another is Memcache. This class serves as a wrapper to abstract functionality to allow you to be technology agnostic. Ideally so you can swap out the underlying caching system without changing application code.
However, by abstracting you can lose functionality specific to a technology. So the Redis class is specific to Redis. If you require Redis specific functionality, you'd need to use this class directly.

Caching support for mutitenant enviornment

I have a use-case where I want to "partition" the cache. I've tried using spring annotation based caching. It works fine for a single tenant application.
E.g. The name of the cache in #Cachable is fine, but I want the interceptor to call a CacheResolver class which resolves the end-cache name based on some other contextual metadata I provide through my application.(For example tenant identifier)
The use-case for this is that I want several cache instances which cache the same info, but several different instances to have an isolated instance for each tenant (multitenant environment). This way I can size them suitable for each tenant - but still keep my code/metainfo quite so clean.
Any help would be greatly appreciated.

Is there a provider agnostic way of getting up to date cache statistics in Spring framework?

Spring provides a useful feature of Cache Abstraction
But what I could not find is a provider agnostic way to get live cache statistics. Essentially I just want to show a list of all the cache names and their corresponding keys with the count of hits, misses, and sizes (in kb) either on a web page or via JMX. I know Ehcache does provide this feature and if I use ehcache API inside the code I can get it (have already used it in the past). But I believe using Ehcache API inside the code takes away the whole notion of the Spring framework's cache abstraction.
The only common, provider-agnostic thing you have is CacheManager interface, which provides the following method:
Collection<String> getCacheNames()
It returns a collection of the caches known by the cache manager.

Resources