FuelPHP Cache visibility between task & app controller - caching

I use memcache as cache driver and I noticed that my app does not see \Cache::set('key', $value); saved in the task. When I try to read it from the app controller level the \Cache::get('key') is not set.

There is no memcache cache driver available in the FuelPHP framework.
If you mean "memcached" (which is not the same), then assuming your config is ok and both the webserver and the commandline use the same config, that should work without problems.

Related

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.

problem in clearing Laravel5.7 cache (memcached driver)

I have upgraded my application laravel version to 5.7 . cache driver is memcached. also i'm using docker compose with separate container for memcached, application, and webserver.
When I try cleaning cache it returns Failed to clear cache. Make sure you have the appropriate permissions.
when I change the cache driver to file it works well. Also, when I'm not running it in docker space it works well!
The problem is probably about flushing memcached. because when i try to clear it manually in my application it returns error 19 which stands for Memcached::RES_SOME_ERRORS! and I dont know what this means exactly!
p.s. and yes, I've created the data folder in storage/framework/cache directory with appropriate permissions.
Any suggestion?
I am assuming you are trying to set up a routine cronjob to clear the cache.
Try running the clear command while you're logged on in a wheel user account
sudo php artisan cache:clear
If it works, you may need to set up that cacheclear on an account with an appropriate access level for memory management tasks.
as I'm using docker i should define hosts as conatiner names.
so I defined MEMCACHED_HOST=memcached in .env file :-"
also i defined application dependency for memcached container.

Using Session with Schedule

I'm using Laravel 5.2.29 and I've set up some scheduled commands.
One of them uses some methods used in my app through normal use (i.e., via a browser) and so the session is accessible.
However, when I try and run the command manually using artisan schedule:run, I get the following exception:
Session store not set on request.
The Session isn't being set (I suppose in the same vein as if a route were accessed without the web middleware), so is there a way to manually boot up the Session? I'd rather not rewrite my methods to not use it.
You don't have access to the session in CLI. Session is strictly connected with the web browser (client side) which doesn't make sense in command line.
If You need a local storage (for server side) You can try with cache driver.

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/

How do I disable Symfony from writing _sess files to my /tmp directory

I am new to symfony and am responsible for a site that I didn't build. For some reason the site is on a live server but running in dev mode. - Im not sure why??
That aside - The website keeps writing _sess files to my /tmp directory. The contents of each _sess file is exactly the same. See below:
_symfony2|a:3:{s:10:"attributes";a:0:{}s:7:"flashes";a:0:{}s:6:"locale";s:2:"en";}
Do I really need all of these files? Can anyone suggest a way of disabling this feature?
Thanks in advance
The default session storage of Symfony2 writes the session information to file(s). The location these files are written to is determined by the config parameter framework.session.save_path. The default value for this is %kernel.cache.dir%/sessions. This means that in a default installation of symfony the session files would be written to the cache directory for the environment.
However, this can be a problem as the cache directory has to be cleared each time an app is deployed, thus logging all the users out. Therefore presumably your app has been configured (most likely in config.yml) to store the session files in /tmp.
As I understand it, sessions that have expired should be garbage-collected at some point. Symfony also has some config params that affect this - see the FrameworkBundle Configuration. I don't know how much traffic your website has but obviously you do need the session files for active sessions. If you think you have a lot of expired sessions you could try tweaking the gc config params.
Alternatively, if having the session files in /tmp is specifically the problem you could relocate them (by changing the value of the framework.session.save_path) or use PDOSessionHandler to store sessions in the database.
I have this problem with symfony 1.4.20 on a web site I inherited.
It is writing files to
/var/lib/php/sessions
every second, until the server runs out of iNodes.
I've tried changing settings in settings.yml. app.yml and PHP session variables.
Nothing sees to be working though, the only way I can stop it is to change the ownership of /var/lib/php/sessions to root and that prevents any session files being created.

Resources