SID-02210: Using VarCache with Include - Or Alternate Best Practice
| Status: |
Answered |
TWiki version: |
6.0.1 |
Perl version: |
|
| Category: |
VarCachePlugin |
Server OS: |
|
Last update: |
9 years ago |
I'm trying to understand the "best" way of accomplishing something but I'm struggling understanding a few things.
My scenario is a topic that contains a Bill of Materials. Let's say it contains 25 individual parts.
My desire is to create a new topic that takes the "raw" data in the Bill of Materials topic and displays it in a "nicer" format. For example, I would like the Part Number column to be a link directly to the topic containing the drawing for that part.
What I'm currently doing is creating a HASH that links each part number to a topic which is then used in a regex search to create the "nicer" format of the Bill of Materials.
I was hoping that I would be able to create the HASH in a topic that is cached and then INCLUDE that topic in my "nicer" Bill of Materials topic to improve speed however it does not seems that cached topics can be used in an INCLUDE.
As a test I've created a topic (
CacheInclude) that contains:
This is a cached topic. The time is: %DISPLAYTIME%.
Another topic (
CacheTest) contains:
%INCLUDE{"CacheInclude"}%
The time is: %DISPLAYTIME%
Although
CacheInclude shows the VARCACHE plugin operating successfully, once it's used in an INCLUDE it is not cached. The output of
CacheTest is always the two DISPLAYTIME values matching.
Any help or direction is much appreciated. Am I using the varcache plugin incorrectly? Is there a between way of creating a "Standard hash" that can be used my many topics without requiring that hash be update on each page load?
--
Jani Hamalainen - 2016-06-14
Discussion and Answer
The
VarCachePlugin only caches variables in the current topic, not included topic. However, since the result of the INCLUDE itself is cached, the included topic topic content should be cached with it.
You could use the
SetGetPlugin to persistently cache data, including hashes. You would create a topic that refreshes the cache, and in your dashboard topic you would simply referenced those persistent variables.
Yet another option is to cache data in the user's browser. See
JStorageContrib.
In terms of parts management, I recommend creating a
TWikiForms-based application. That gives you a lot of flexibility in data manipulation, formatting and reporting. See
How to Create a TWiki Application
--
Peter Thoeny - 2016-06-24
Thanks for the info on
SetGetPlugin. I understand the scenario that you explained where a topic creates the hash and then another topic calls the variable set within the hash creation topic.
I'm struggling with understanding how to use
SetGetPlugin to store a hash. I've created two topics in the Sandbox (
GetSetPluginVariableCreation and
TestingGetSetPlugin) where I've tried creating a hash and storing it using
SetGetPlugin however I'm unfortunately missing something in my understanding.
Also, to address your comment about using a
TWikiForms-based application. I've created an application using
TWikiForms that creates a topic for each part (including PDF drawing and other part particulars). The Bill Of Materials I'm trying to create would pull content for each line based upon the hashes I'm trying to store.
Finally, a question regarding
SetGetPlugin. Is there a way to remove a variable once it's been created? Doing some testing on my local installation quickly grew the quantity of persistent variables in
SETGETDUMP.
--
Jani Hamalainen - 2016-06-28
My best effort so far that works is converting the hash to a list as shown:
%SET{ "FarmAnimalsVariableHash2List" value="%CALCULATE{$HASH2LIST(FarmAnimals)}%" store="StoreName" }%
Then in the topic where I want to use the variable I convert it back into a hash:
%CALCULATE{$LIST2HASH(FarmAnimalsHash2List, %GET{ "FarmAnimalsVariableHash2List" store="StoreName" }%)}%
Is this the
best way of adding a hash to a
SetGetPlugin variable?
--
Jani Hamalainen - 2016-06-28
There is no web-based way to remove
SetGetPlugin variables, short of storing an empty value. You can however edit the store on the file system. Look into the plugin's working directory.
Storing a hash as a list, then converting back is a good way to do. Alternatively, store the hash as a JSON object, e.g. to construct this:
%SET{ name = { "key1": "value1", "key2": "value2", ... } remember="1" }%
use a CALCULATE:
%SET{ name = { %CALCULATE{ $LISTEACH("$item": "$GETHASH(animals, $item)", $GETHASH(animals)) } remember="1" }%
Yet another way is to prepare and store the final text you want to show eventually to the user.
See also:
--
Peter Thoeny - 2016-06-29
Thanks for the info Peter. For anyone viewing this topic the
SetGetPlugin persistent variables are stored in:
/var/www/twiki/working/work_areas/SetGetPlugin/persistentvars.dat
--
Jani Hamalainen - 2016-06-29
If you answer a question - or someone answered one of your questions - please remember to edit the page and set the status to answered. The status selector is below the edit box.