Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-48506

Improve memcached cache store so that it is multi-site safe

    XMLWordPrintable

    Details

    • Testing Instructions:
      Hide

      Pre-test Setup

      • Install / upgrade the memcached php extension (php5-memcached) version 2.0.0 or greater
        • Note: remember to restart apache after installing / upgrading the extension).
      • Make sure memcached is installed and the server is running.
      • Make sure your site is not in dev mode (so that is uses the cache).

      Helpers: How to add a test cache entry from CLI

      • telnet into your memcached server
        • If it's running locally with default ports you can do telnet 127.0.0.1 11211
      • Type set test 0 3600 1 hit "enter" then type 1 - you should see "STORED"
      • This cheat sheet is helpful

      Helpers: How to see a cache entry from CLI

      • telnet into your memcached server (see above)
      • Type get <keyname> e.g. get test - you should see the value printed (if the key exists) then "END"
      • This cheat sheet is helpful

      Helpers: How to see the cache items from CLI

      • telnet into your memcached server (see above)
      • Type stats items

      Test 1 - Old extension version (existing behaviour)

      1. You can either downgrade your php5-memcached extension to below v2.0.0 or you can modify the code to simulate and old version
        1. To simulate you can set this variable to "false" and this property to "false"
      2. Log into your site as admin
      3. Go to the cache configuration (Site administration > Plugins > Caching > Configuration) and click "Add instance" next to memcached
      4. You should see a notice at the bottom of the form telling you to upgrade your php memcached extension
      5. You should not see a "Shared cache" form option
      6. Fill in the details and add the instance
      7. Map the string cache to the new instance you've created
      8. Browse around a little and make sure strings are being rendered correctly (i.e. the cache is being accessed)
      9. Look at the memcached items from CLI, you should see lots of entries
      10. Create a test entry from the CLI (key can just be "test")
      11. Purge the cache instance (from the caching configuration page)
      12. Print the cache key from the CLI
      13. Confirm that your test entry was deleted (this means the entire cache was purged, non Moodle data wasn't preserved)

      Test 2 - Non-shared cache - Full cache purge

      1. Revert your changes from step one in "Test 1" (i.e. upgrade your extension version or revert your code changes)
      2. Edit the memcached instance you created in "Test 1"
        • Site administration > Plugins > Caching > Configuration - The "Configured store instances" section
      3. Confirm: You do not see the upgrade extension notice
      4. Confirm: You see a "Shared cache" option
      5. Set the "Shared cache" option to "No"
      6. Repeat "Test 1" from step 8 to confirm that the entire cache is flushed when using a dedicated cache

      Test 3 - Shared cache - Selective cache purge

      1. Edit the memcached instance from "Test 1" again
      2. Change "Shared cache" to "Yes"
      3. Repeat "Test 1" from step 8 however this time your "test" key should not have been deleted by the purge, it should still exist in the cache after purging the Moodle cache (this simulates another application adding entries to the cache).

      Test 4

      1. Start a second instance of the memcached server on a non-default port (default port is 11211 I use 11212 for my second instance)
      2. Run unit tests on cache/stores/memcached/tests/memcached_test.php
      3. Add the following to your config.php
        • define('TEST_CACHE_USING_APPLICATION_STORE', 'memcached');
        • define('TEST_CACHESTORE_MEMCACHED_TESTSERVERS', '127.0.0.1:11212'."\n".'127.0.0.1:11211');
      4. Run full unit test suite (CiBot cant do this for you because of the above defines)
      5. Done - congrats!
      Show
      Pre-test Setup Install / upgrade the memcached php extension (php5-memcached) version 2.0.0 or greater Note: remember to restart apache after installing / upgrading the extension). Make sure memcached is installed and the server is running. Make sure your site is not in dev mode (so that is uses the cache). Helpers: How to add a test cache entry from CLI telnet into your memcached server If it's running locally with default ports you can do telnet 127.0.0.1 11211 Type set test 0 3600 1 hit "enter" then type 1 - you should see "STORED" This cheat sheet is helpful Helpers: How to see a cache entry from CLI telnet into your memcached server (see above) Type get <keyname> e.g. get test - you should see the value printed (if the key exists) then "END" This cheat sheet is helpful Helpers: How to see the cache items from CLI telnet into your memcached server (see above) Type stats items Test 1 - Old extension version (existing behaviour) You can either downgrade your php5-memcached extension to below v2.0.0 or you can modify the code to simulate and old version To simulate you can set this variable to "false" and this property to "false" Log into your site as admin Go to the cache configuration (Site administration > Plugins > Caching > Configuration) and click "Add instance" next to memcached You should see a notice at the bottom of the form telling you to upgrade your php memcached extension You should not see a "Shared cache" form option Fill in the details and add the instance Map the string cache to the new instance you've created Browse around a little and make sure strings are being rendered correctly (i.e. the cache is being accessed) Look at the memcached items from CLI, you should see lots of entries Create a test entry from the CLI (key can just be "test") Purge the cache instance (from the caching configuration page) Print the cache key from the CLI Confirm that your test entry was deleted (this means the entire cache was purged, non Moodle data wasn't preserved) Test 2 - Non-shared cache - Full cache purge Revert your changes from step one in "Test 1" (i.e. upgrade your extension version or revert your code changes) Edit the memcached instance you created in "Test 1" Site administration > Plugins > Caching > Configuration - The "Configured store instances" section Confirm: You do not see the upgrade extension notice Confirm: You see a "Shared cache" option Set the "Shared cache" option to "No" Repeat "Test 1" from step 8 to confirm that the entire cache is flushed when using a dedicated cache Test 3 - Shared cache - Selective cache purge Edit the memcached instance from "Test 1" again Change "Shared cache" to "Yes" Repeat "Test 1" from step 8 however this time your "test" key should not have been deleted by the purge, it should still exist in the cache after purging the Moodle cache (this simulates another application adding entries to the cache). Test 4 Start a second instance of the memcached server on a non-default port (default port is 11211 I use 11212 for my second instance) Run unit tests on cache/stores/memcached/tests/memcached_test.php Add the following to your config.php define('TEST_CACHE_USING_APPLICATION_STORE', 'memcached'); define('TEST_CACHESTORE_MEMCACHED_TESTSERVERS', '127.0.0.1:11212'."\n".'127.0.0.1:11211'); Run full unit test suite (CiBot cant do this for you because of the above defines) Done - congrats!
    • Affected Branches:
      MOODLE_29_STABLE, MOODLE_31_STABLE
    • Fixed Branches:
      MOODLE_31_STABLE
    • Pull Master Branch:
      MDL-48506-master
    • Sprint:
      3.1 Sprint 7
    • Issue size:
      Large

      Description

      It should be possible to make the memcached cache store multi-site safe.
      This should be done 100%.

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                6 Vote for this issue
                Watchers:
                19 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Fix Release Date:
                  23/May/16