Log in | Register



Cached worksheets

This sample, which is saved as Cached worksheets in the Samples subfolder of the Resolver One folder on your Start Menu, introduces you to the cached worksheets.

Cached worksheets are persistent between recalculations, so they can be used to store values that take long time to compute. Avoiding lengthy calculations can make subsequent recalculations faster. This sample demonstrates a typical pattern of their usage by performing long calculation (getting the approximate answer to Life, the Universe, and Everything) and storing the result in cache. The Pre-formulae user code looks as follows:

from random import random
from System.Threading import Thread

def AnswerToLifeTheUniverseAndEverything():
    Thread.Sleep(5000) # what was the question again?
    return 42 + random() - 0.5

cachedWS = workbook.AddWorksheet('cache', WorksheetMode.Cache)
cachedWS.Visible = True

if cachedWS.A1 is Empty:
    cachedWS.A1 = AnswerToLifeTheUniverseAndEverything()

answer.Value = cachedWS.A1

This will create a cached worksheet called 'cache' if one does not already exist. If the worksheet exists, the worksheet (complete with the data stored in it during the last recalculation) will be returned.

Cached worksheets are invisible by default. Setting their Visible property to True will make them visible. They will then appear as one of the worksheet tabs. In the worksheet tab the cached worksheet will have '(RESULT)' appended to the name. This indicates that the worksheet is a result-only worksheet and cannot be editted like an ordinary worksheet. Result-only worksheets can only be changed from user code and not through the Resolver One grid interface. This extends to deleting them: You cannot delete a result-only worksheet by right-clicking on its tab and choosing 'Delete Worksheet'. To remove a cached worksheet, simply remove the code that creates it and recalculate.

Use Data -> Delete Cache Worksheets menu item to recalculate the answer. Note that it takes Resolver One only 5 seconds to come up with the results that took Deep Thought 7.5 million years to calculate.

Back to Sample Spreadsheets.

Comments