2

I'm developing a ColdBox application with modules and wanted to use it's caching functionality to cache a view for some time.

component{
  property name="moduleConfig" inject="coldbox:moduleConfig:mymodule";

  ...

  function widget(event, rc, prc){
    var viewData = this.getData();

    return renderView(
      view = "main/widget",
      args = viewData,
      cache = true,
      cacheSuffix = ":" & moduleConfig.entryPoint,
      cacheTimeout = 2
    );
  }
}

I tried to set the default caching config by adding the following info to my Cachebox.cfc and removed the cacheTimeout from the code above:

cacheBox = {
  defaultCache = {
    objectDefaultTimeout = 1, //two hours default
    objectDefaultLastAccessTimeout = 1, //30 minutes idle time
    useLastAccessTimeouts = false,
    reapFrequency = 5,
    freeMemoryPercentageThreshold = 0,
    evictionPolicy = "LRU",
    evictCount = 1,
    maxObjects = 300,
    objectStore = "ConcurrentStore", //guaranteed objects
    coldboxEnabled = false
  },

  caches = {
    // Named cache for all coldbox event and view template caching
    template = {
      provider = "coldbox.system.cache.providers.CacheBoxColdBoxProvider",
      properties = {
        objectDefaultTimeout = 1,
        objectDefaultLastAccessTimeout = 1,
        useLastAccessTimeouts = false,
        reapFrequency = 5,
        freeMemoryPercentageThreshold = 0,
        evictionPolicy = "LRU",
        evictCount = 2,
        maxObjects = 300,
        objectStore = "ConcurrentSoftReferenceStore" //memory sensitive
      }
    }
  }
};

Though that didn't have any influence on the caching. I've also tried to add the config above to my Coldbox.cfc.

Even if I create a completely new test app via CommandBox via coldbox create app MyApp, then only set the the caching in Cachebox.cfc to one minute, set viewCaching = true in Coldbox.cfc, and set event.setView( view="main/index", cache=true ) in the Main.cfc, it doesn't work as expected.

No matter what I do, the view is always cached for at least 5 minutes.

Is there something I am missing?

Sebastian Zartner
  • 18,808
  • 10
  • 90
  • 132
  • How are you confirming the amount of time the view is being cached for? – Brad Wood Feb 16 '17 at 20:38
  • Since this question is cross-posted in the CFML slack team, I've replied to you there (I can't reproduce). Once we figure out what your issue is, we can come back and update an answer here since SO is really suited for back and forth Q & A. – Brad Wood Feb 16 '17 at 21:24

2 Answers2

1

Make sure you have enabled view caching in your ColdBox configuration. Go to the /config/ColdBox.cfc file and add this key:

coldbox = {
  // Activate view caching
  viewCaching = true
}

Also, did you mistype the name of the CFC you changed for the caching above? Those changes should be in the /config/CacheBox.cfc file, not in /config/ColdBox.cfc.

  • No, `viewCaching = true` doesn't change this, unfortunately. I initially had the config in `/config/Cachebox.cfc`, then moved it for test purposes to `/config/Coldbox.cfc`. The view is always cached for 5 minutes. I've updated my question with that info. – Sebastian Zartner Feb 16 '17 at 13:49
0

Obviously, also the the reapFrequency in the /config/ColdBox.cfc needs to be set to a smaller value in order to let the cache entry be removed earlier.

Though, as the documentation states:

The delay in minutes to produce a cache reap (Not guaranteed)

It is not guaranteed that the cached item it really removed after that time, so it can be that the cache is empty after 3 minutes even when reapFrequency is set to 1.

Sebastian Zartner
  • 18,808
  • 10
  • 90
  • 132