How to use alfresco hazelcast caches for storing custom data objects

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Active Member

How to use alfresco hazelcast caches for storing custom data objects

We are in  requirement of storing custom object (Map<String><String>) in caches with some customName(NodeId) in alfresco.

Eg: When the user first time invokes custom action in certain node, data will be created in the form of Map and that needs to be stored in cache with region name as nodeId.

The same data needs to be retrieved from cache using nodeId when user second time invokes same action in the same node . 

And all the caches needs to be cleared automatically with in some pre configured time.

I guess probably we need to use hazelcast to achieve this, but I cannot able to find the proper documentation for this purpose.

Can someone guide me with the best approach ?

4 Replies
Highlighted
Master

Re: How to use alfresco hazelcast caches for storing custom data objects

You should not have to and never should use Hazelcast as a direct dependency in your Alfresco code. Alfresco already provides a generic abstraction for caches which - on Enterprise installations - may use Hazelcast as the underlying library.

You simply have to define your custom cache as beans using the Alfresco cache factory and a transactional cache to go along with it to correctly deal with on-commit cache updates. In the beans where you want to use a cache you inject the transactional cache (using SimpleCache<String, String> as type of dependency). Finally, you have to configure some properties for how the cache should behave in your module alfresco-global.properties file. This is also where you effectively determine that the cache uses Hazelcast on Enterprise installations by setting the cluster type - only "fully-distributed" actually will make Alfresco use a pure Hazelcast cache, "invalidating" uses a simple map with Hazelcast-based messaging, and "local" is just that simple map.

Highlighted
Active Member

Re: How to use alfresco hazelcast caches for storing custom data objects

Hi Axel

Thanks for the reply.

We would like to generate cache in runtime (i.e) the name should be with nodeId.

   ( i.e) We like to add cache object dynamically with nodeId as the key when the user access the node first time through the custom Action.

The methods you mentioned is something which we need to configure before starting server.

Do we have any approach to achieve this in  alfresco.

Thanks

Highlighted
Master

Re: How to use alfresco hazelcast caches for storing custom data objects

It does not make any sense to generate a cache instance during runtime for individual nodes based on their IDs. If you have a system with a million nodes you'd (eventually) end up with a million cache instances.

As far as you have described it, your use case would work with a single pre-configured instance. If you have a custom action you should already have some custom Java code (or are you talking about a script action here?) which is configured before starting the server (via an extension / Spring config), and you'd simply add a cache to that implementation, putting in cache data keyed by the NodeRef (you should never rely on node ID in custom code).

Whatever you want to cache, please be aware that you will have to deal with cache data invalidation yourself when changes are made to properties / content that you are caching...

Highlighted
Active Member

Re: How to use alfresco hazelcast caches for storing custom data objects

Hi Axel 

Thanks for your reply.

It does not make any sense to generate a cache instance during runtime for individual nodes based on their IDs. If you have a system with a million nodes you'd (eventually) end up with a million cache instances.

We will not use this cache for all nodes. It will be used only for certain file types which is very less in number.

As far as you have described it, your use case would work with a single pre-configured instance. If you have a custom action you should already have some custom Java code (or are you talking about a script action here?) which is configured before starting the server (via an extension / Spring config), and you'd simply add a cache to that implementation, putting in cache data keyed by the NodeRef (you should never rely on node ID in custom code).

 

Whatever you want to cache, please be aware that you will have to deal with cache data invalidation yourself when changes are made to properties / content that you are caching...

The reason we want to put it based on node Id is, we stored metadata of certain files  in another system. We just want to get the metadata from the other system only one time (At very first time any of the user access the custom Action on particular node).

The next time if some other user accesses the same action in same node, we dont want to make another call to get the metadata again.

As  you said we if pre configure the cache with some generic name and internally keyed with nodeRef, when we invalidate the cache it will remove all the cached data (Includes all nodeRef and cachedata(metadata) key value pairs- Pls correct me if I am wrong). 

We want to specifically invalidate custom cache related to particular nodeRef alone . 

So I am seeking for some  option to create cache object in runtime and invalidation period also need to specified at the time of creating object.

Thanks

Vijay S