Welcome Guest, Not a member yet? Register   Sign In
Caching improvements
#1

Hello,
I'm new to CodeIgniter, liking what I'm seeing so far, but some caching things are standing out to me.  I'd like to create a pull request to address these things but wanted to run it by everyone else first to ensure it wouldn't be rejected in case it runs counter to what the intended approach is, or there's some other kind of consideration.
  • Caching configuration is kind of a mess IMHO.  Caching config should be an environment-specific thing (e.g. use redishost01 for domain x, use redishost02 for domain y), but instead cache connection configuration is embedded in the code.  Database configurations, however, are stored in the .env file, making things much easier to configure for a given environment.  I'd like to make the cache configurable like the database is configurable in the .env file, but preserve the way it's currently handled to maintain backwards compatibility.
  • To further complicate things, if I want to use redis as my session store, I have to setup the connection in the .env file, in a completely different manner than how I configure the cache handler, despite already having redis configured as a cache driver.  I know that a cache handler and a session handler are separate entities, but it would be simple to be able to tell the session handler to use whatever the configured cache handler is.
  • Redis Cluster compatibility.  Based on what I see in the redis handler classes for cache & session, it's only creating a Redis() class, not a RedisCluster() class.  In cluster mode, an individual server will prompt the client to connect to a different node and re-run the command, based on wherever the key slot is determined to be.  If CodeIgniter4 were to be connected to a redis cluster, it would definitely have issues.
  • Redis serialization.  Looks like CI stores each individual key as a hash with __ci_type and __ci_value.  I think this is unnecessary.  Using the phpredis driver, we can call $redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP), and from then on, any data going into the cache will be serialized with php's serializer, any data coming out of the cache will be unserialized, so all of our data will be stored in the cache as it is in php.  I think this a) would remove overhead associated with determining and storing the type of the data we cache (for ci type/value), and b) would remove overhead of CI storing literally everything as hashes instead of normal keys.
If anyone sees any reasons these changes shouldn't be made, please let me know.  Otherwise I'd like to get a PR going.  Thank you!
Reply
#2

(This post was last modified: 12-10-2021, 04:58 AM by kenjis.)

All Config classes can be configurable in the .env file.
See https://codeigniter4.github.io/CodeIgnit...-variables

Does not work?

PHP Code:
REDIS_HOST localhost
REDIS_PORT 
6379
cache
.redis.host "${REDIS_HOST}"
cache.redis.port "${REDIS_PORT}"
app.sessionSavePath "tcp://${REDIS_HOST}:${REDIS_PORT}
Reply
#3

Thank you! Didn't realize that was possible but it's very helpful. I missed that in the docs.
Unless there's any reason not to, I'm going to go ahead and work on cluster compatibility and using the php serializer.  I think those would be helpful contributions.
Reply
#4

I think cluster compatibility and the php serializer would be great additions. Thanks! We look forward to seeing the PR.
Reply
#5

(12-10-2021, 08:11 AM)stevenmalin Wrote: Unless there's any reason not to, I'm going to go ahead and work on cluster compatibility and using the php serializer.  I think those would be helpful contributions.

Yes, those would be great contributions!
Reply
#6

Does anyone know if Redis cluster support was ever integrated into Codeigniter?
Reply
#7

No. The PR was closed.
https://github.com/codeigniter4/CodeIgniter4/pull/5519
Reply




Theme © iAndrew 2016 - Forum software by © MyBB