Publisher does not support the Fluid field type. Please do not contact asking when support will be available.

If you purchased an add-on from expressionengine.com, be sure to visit boldminded.com/claim to add the license to your account here on boldminded.com.

Ticket: Caching issues with Custom System Messages + fixes

Status Resolved
Add-on / Version Custom System Messages 3.0.5
Severity
EE Version 5.3.2

Hop Studios

Dec 21, 2023

Hey Brian,

I was reviewing CSM for a client we have it installed for and noticed that I had done a couple tweaks to the code to get around a bug I noticed with caching the settings.

It was last year some time and I should have reported it then, but the fix worked for our purposes. I think perhaps the changes were not sticking properly when made, or something along those lines.

I’ll share the code here for your reference and perhaps you could review the current 3.0.5 code and see if my bug and fix make any sense!

# 2021-09-07 Rowan Sentesy
Fix caching issue in system messages.

contentzsystem/user/addons/system_messages/ext.system_messages.php
line 613-628

```
OLD:

// Get the settings for the extension
        if(isset($this->cache['settings']) === FALSE || $force_refresh === TRUE) {
            // check the db for extension settings
            $query = ee()->db->query("SELECT settings FROM exp_extensions WHERE enabled = 'y' AND class = '" . __CLASS__ . "' LIMIT 1");

            // if there is a row and the row has settings
            if ($query->num_rows() > 0 && $query->row('settings') != '') {
                // save them to the cache
                $this->cache['settings'] = strip_slashes(unserialize($query->row('settings')));
            }
        }

        // check to see if the session has been set
        // if it has return the session
        // if not return false
        if(empty($this->cache['settings']) !== TRUE) {
            $settings = $this->cache['settings'];
        }


NEW:

$cache_key = '/SystemMessages/Settings';
        $settings = ee()->cache->get($cache_key, 1);

        if (empty($settings) || $force_refresh === TRUE) {
            $query = ee()->db->query("SELECT settings FROM exp_extensions WHERE enabled = 'y' AND class = '" . __CLASS__ . "' LIMIT 1");

            // if there is a row and the row has settings
            if ($query->num_rows() > 0 && $query->row('settings') != '') {
                // save them to the cache
                $settings = strip_slashes(unserialize($query->row('settings')));
                ee()->cache->save($cache_key, $settings, 14400, 1);
            }           
        }


```

# 2022-03-17 Rowan Sentesy
Fix caching issue in system messages on settings save.
contentzsystem/user/addons/system_messages/ext.system_messages.php
line 539-542

Added:
```

// Save our settings to the current site ID for MSM.
        $site_id = ee()->config->item('site_id');
        $settings = $this->global_settings;
        $settings[$site_id] = $insert;

```


Rowan

#1

BoldMinded (Brian)

Thanks for the detailed report. I’ll take a look at this.

#2

BoldMinded (Brian)

This has been fixed in the latest release.

Login to reply