How to add entries in Application.conf during runtime? - caching

How to add separate redis cache instances at runtime?
Manually one can add multiple redis cache instances in this way
Application.conf:
redis.uri="redis://192.168.3.170:6000"
# disable default Play framework cache plugin
play.modules.disabled = ["play.api.cache.EhCacheModule"]
# enable redis cache module
#play.modules.enabled = ["play.api.cache.redis.RedisCacheModule"]
#Multiple redis caches
play.cache.redis.bindCaches = ["cache1","cache2","cache3"]
How if I need to add one more cache say cache4 during runtime?
I have tried through ConfigFactory.load.entrySet() and Config class.

You can't do it since Config is immutable. Also, keep in mind that your redis cache implementation would need to listen to configuration changes in order to recognize the new cache.
Maybe a better way is to have this built into Redis module. In other words, you would be able to do something like redis.addCache("cache4").

Related

How do you set the cache prefix per cache driver in Laravel

I maintain a microservice architecture where some of the contained services are required to read from more than one cache service.
The cache prefix across these different cache services is different and as such, I need to set a different cache prefix for each cache service in my Laravel project otherwise Laravel uses a global prefix defined in the cache.php config file.
Here you can see the global Cache Prefix setting:
How do I set this per driver? ie: Redis, DynamoDB
After my own trial and error, I have found that you simply add a 'prefix' key to the driver in the cache.php file as such:
I could not find this instruction in Laravel's documentation.

How to update Abp Permission Cache for each application

I have multiple services (Administration.Api, Project.Api)
Administration service is managing permissions (create,update).
But i have a problem about caching, when i update permissions through Administration.Api, Project api's cache Permission grant don't change immediately(it's grant change after 20minutes, when cach removed automatically)
I want to change all permission cache under different cache prefixes immediately. How can i fix this?
You really need a true distributed cache service (like Redis) to do this properly. That way a cache-dump for one affects all services.
There are other solutions you could try, but really they are just bandaids, and more work with potential other sideeffects.
use a message bus to notify all services of the permission change and to dump their in-memory cache
use a new shared db table to add a new row with "LastUpdated". The permission service would need to write the updated time when permissions changed. Each service would need to query this table to check for a newer updated time (on each request), and dump in-memory cache if exists.
You can use AbpDistributedCacheOptions to change default cache settings and add prefix to your application for caching.
Configure<AbpDistributedCacheOptions>(options =>
{
options.GlobalCacheEntryOptions = new DistributedCacheEntryOptions()
{
AbsoluteExpiration = //20 mins default
};
options.KeyPrefix = "MyApp1";
});
You can also extend override permission management providers, such as RolePermissionManagementProvider and handle cache invalidation.
Docs about permission management providers: https://docs.abp.io/en/abp/latest/Modules/Permission-Management#permission-management-providers
One application has ONE ABP default cache (we are not talking about global caches like Redis now). So to have a single control of different applications caches, you can use RabbitMQ: you have a RabbitMQ queue in each application, named something like "abp-cache[appName]". In RabbitMQ receiver, you send messages to EACH of these queues. In the RabbitMQ receiver of the specific app, you handle the received message. I've already implemented this mechanism to update ABP permission cache for all my apps. Everything is easily wrapped inside Extensions Nuget package.

Disabling/Pause database replication using ML-Gradle

I want to disable the Database Replication from the replica cluster in MarkLogic 8 using ML-Gradle. After updating the configurations, I also want to re-enable it.
There are tasks for enabling and disabling flexrep in ML Gradle. But I couldn't found any such thing for Database Replication. How can this be done?
ml-gradle uses the Management API to handle configuration changes. Database Replication is controlled by sending a PUT command to /manage/v2/databases/[id-or-name]/properties. Update your ml-config/databases/content-database.json file (example that does not include that property) to include database-replication, including replication-enabled: true.
To see what that object should look like, you can send a GET request to the properties endpoint.
You can create your own command to set replication-enabled - see https://github.com/rjrudin/ml-gradle/wiki/Writing-your-own-management-task
I'll also add a ticket for making official commands - e.g. mlEnableReplication and mlDisableReplication, with those defaulting to the content database, and allowing for any database to be specified.

How to configure the TTL for the ZF2 file based config and module map cache?

In Zend Framework 2 it's possible to bundle all the configs as a merged array in on file. The same can be done for the module class map. It increases the performance a bit and is easy to set up (see also the documentation):
/config/application.config.php
return array(
...
'module_listener_options' => array(
...
'config_cache_enabled' => true,
'config_cache_key' => 'app_config',
'module_map_cache_enabled' => true,
'module_map_cache_key' => 'module_map',
'cache_dir' => './data/cache',
),
);
The cache is file based (at least I didn't find a way to use a memory based cache like memcached).
Is it possible / How to to define a time to live to the config cache in Zend Framework 2?
Yes, the cache is file based. For the sole reason, this is the configuration used before bootstrapping the app. Thus, loading Zend\Cache with all bits isn't an ideal case (as you preferable want to use a service manager config, after the service manager is configured, but you're still prior to bootstrapping).
All configs in ZF2 are files, so the easiest way is actually merge all files together and write them into a single file.
Next, TTL for this cache doesn't really make sense. You only have cache invalidation when you change your (file based!) module configuration. The only reason you change your config files is during deploys. After all, on dev and testing environments you don't cache configs and on production you only work with proper deployments (you are, right? ;) ).
The proper solution is therefore not to look at TTL but rather solve the cache invalidation during deployment. If you overwrite your app with new files, remove the cache. If you deploy a new version of you app in a new folder (capistrano alike) you don't have this problem at all.

How to change Infinispan cache settings after it is created?

In my application i'm using Infinispan 5.3 version and I want to change setting after cache is initialized. Default settings will be loaded from xml file and some of the settings ( ex : eviction maxEntries, lifespan, etc ) should be able to change any time of application running (This is changed by sysadmin). Is there way to changed settings of already created cache ?
I tried EmbeddedCacheManager.defineConfiguration(String cacheName, Configuration configurationOverride); but this has no effect on already created cache.
Please, take into account that in the Infinispan version 5.3 there is no possibility to change cache configuration "on the fly". You need to restart your service with new configuration in case of any wanted change.
This is something the community might want to work on in the future. However, such a task is not easy because you need to figure out how to correctly deal with affected data immediately after the configuration change.
Feel free to raise new feature request: https://issues.jboss.org/browse/ISPN/

Resources