CodeIgniter Forums
Transient support for Settings - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Feature Requests (https://forum.codeigniter.com/forumdisplay.php?fid=29)
+--- Thread: Transient support for Settings (/showthread.php?tid=90493)



Transient support for Settings - joho - 03-26-2024

Sorry if this has been covered elsewhere or by other features.

It'd be nice if settings could accept a TTL parameter. Not sure how the best way would be to pass it, but the idea is that a setting can be temporary, a transient.

Expired transients can be removed by CI at any time, and/or by something like service('settings')->forgetTransients() maybe.

So I'd do service('settings')->set('User.Reminder', 'SomeValue', 'SomeContext', 3600) for the setting to live for 3600 seconds.

If I do a service('settings')->get() for this within 3600 seconds, the value is returned, otherwise whatever get() normally returns on a "not found" request is returned.

This is much like WordPress' transients.

I understand this could, probably, be implemented using CI caching, but my point is related to "settings" / "config" only, and temporary values.


RE: Transient support for Settings - kenjis - 03-26-2024

Config classes are essentially have system settings and they are static values.
See https://codeigniter4.github.io/CodeIgniter4/general/configuration.html#what-are-configuration-classes

The use case for temporary values is not clear to me.

In my opinion, "Contextual Settings" feature is not a good feature.
Of course, things like user settings exist, so there is the issue of how to handle them.
But treating system settings and user settings as the same "Config" is confusing.


RE: Transient support for Settings - joho - 03-27-2024

The use case range from settings that are related to a given window of time. Basically, I guess you could say that a setting with no TTL is a permanent setting, whereas a setting with a TTL value is a temporary setting. Transients can be used to create "timers" or "events" that outlast a session, to send reminders, to revert a temporary setting, whatever ...

I definitely agree about the "Contextual settings". Perhaps "User settings" belong in the Auth section of the library.


RE: Transient support for Settings - kenjis - 03-27-2024

Probably you can write a helper function that uses Cache and Settings.
If there is cache, return it. If not, get the value from setting().
If you *override* the setting() function, you can get what you need soon.