SPIP caching

Hello everyone!
Can anybody help me to cope with SPIP caching? Talking about caching I don’t mean squelettes, my question is about programming structures like balises and criterias.
For example, I need criteria witch would influence BOUCLE every time page is calculated.
Also in some cases I want to change static tag (balise) cache time, or even make its output absolutely dynamic.
I tried to find some information on programmer.spip.org, but nothing helped me.
Is it possible at all to avoid caching SPIP static elements?

Thanks in advance,
Yaroshchuk Aleksey.

Hi,

SPIP already offers some mechanisms for making loops more context-dependant :
cf. http://www.spip-contrib.net/how-to-extend-the-capabilities-of-your-loops

You can use #ARRAYS, dynamic variables defined by #SET and #GET, custom functions (called with [(#VAL|my_dynamic_function)] for ex. ).

What do you want to do that can be done with such tools ? You talk about loop and criteria that are not static because they are transformed into PHP functions in the cache of SPIP (you can verify it with the ?var_mode=debug parameter).

Hope it helps,

.Gilles

On Mon, Oct 17, 2011 at 5:39 PM, Алексей Ярощук <a.yaroshuk@aloha.org.ua> wrote:

Hello everyone!
Can anybody help me to cope with SPIP caching? Talking about caching I don’t mean squelettes, my question is about programming structures like balises and criterias.
For example, I need criteria witch would influence BOUCLE every time page is calculated.
Also in some cases I want to change static tag (balise) cache time, or even make its output absolutely dynamic.
I tried to find some information on programmer.spip.org, but nothing helped me.
Is it possible at all to avoid caching SPIP static elements?

Thanks in advance,
Yaroshchuk Aleksey.


spip-en@rezo.net - http://listes.rezo.net/mailman/listinfo/spip-en

Le 17/10/11 17:39, Алексей Ярощук a écrit :

For example, I need criteria witch would influence BOUCLE every time page is
calculated.

Unfortunately, the loops do not have a specific cache, and I think you
have to use the potential of conditional <INCLURE>

Also in some cases I want to change static tag (balise) cache time, or even
make its output absolutely dynamic.

You might find interesting information here :
   http://doc.spip.org/@Balises-dynamiques-trucage-d (in french)
Dynamic tags, fake arguments, and AST mangling in SPIP - Passing Curiosity (in English)

Hi

On Tue, Oct 18, 2011 at 9:33 AM, denisb <denisb@laposte.net> wrote:

Le 17/10/11 17:39, Алексей Ярощук a écrit :

For example, I need criteria witch would influence BOUCLE every time page is
calculated.

Unfortunately, the loops do not have a specific cache, and I think you
have to use the potential of conditional

Conditional inclusion of templates can be done like this :
[(#EVAL{$phpVariable}|=={ok}|oui) <=== whatever conditionnal expression
#INCLURE{fond=inc/block,env} <=== filters (and then custom PHP functions) can be applied on a #INCLURE
]

or with the loop CONDITION than is introduced by the plugin ‹ spip_bonux ›
(you should look at the source of this plugin to see how it works)

#INCLURE returns a static element that is stored in the cache file, on the opposite of that are thansformed into PHP functions –

Another plugin that may interest you is the plugin that introduces iterators :
http://www.spip-contrib.net/Les-Iterateurs-pour-SPIP-2-1 (french doc)
and http://zzz.rezo.net/Les-iterateurs-de-SPIP.html

Its code is a great source of inspiration :wink:

Also in some cases I want to change static tag (balise) cache time, or even
make its output absolutely dynamic.

You might find interesting information here :
http://doc.spip.org/@Balises-dynamiques-trucage-d (in french)

http://passingcuriosity.com/2009/dynamic-tags-fake-arguments-ast-mangling-in-spip/ (in English)

I thought that this coding model was deprecated (especially for the function calculer_balise_dynamique), as it was introduced in SPIP1.9 and recent plugins offer more possibilities . But I’m not sure.

my 2 cents,

.Gilles

Le 18/10/11 10:57, Gilles VINCENT a écrit :

I thought that this coding model was deprecated

Of course it is not !
function calculer_balise_dynamique($p, $nom, $l, $supp=array())
is still used in spip3 (especially for forms processing)

Thanks, that’s a usefull information.
Maybe the hacking that Yaroshchuk Aleksey wants to do can be done by modifying this function (it’s just an idea of course)

On Tue, Oct 18, 2011 at 1:58 PM, denisb <denisb@laposte.net> wrote:

Le 18/10/11 10:57, Gilles VINCENT a écrit :

I thought that this coding model was deprecated

Of course it is not !
function calculer_balise_dynamique($p, $nom, $l, $supp=array())
is still used in spip3 (especially for forms processing)


spip-en@rezo.net - http://listes.rezo.net/mailman/listinfo/spip-en

Thanks for your answers. I will definitely try to use plugin « iterateurs ». According to description it is very useful tool.

I tried to use calculer_balise_dynamique for transforming SPIP-BONUX’s static tag TRI into dynamic, but had no good results. Using this tag is described here: http://www.spip-contrib.net/Utiliser-la-balise-TRI-et-le-crietre-tri-dans-les I wanted to modify this tag with possibility of changing sort order via clicking on table elements. My modifications worked only if I manually cleared cache between clicks. According to this I made a conclusion that problem is in SPIP caching. Eventually I found another decision. If someone is interested, I can describe it.

I’ll keep trying and looking for better solution for this « chaching » problem.

Hi,

can you give us an extract from your code that reproduces your problem ?
This is curious because #TRI and {tri} seems to correspond to your needs

Here is a code that works for me :

#CACHE{0}
<B_>
#PAGINATION

ID TITLE
#ID_ARTICLE#TITRE

On Wed, Oct 19, 2011 at 12:54 PM, Алексей Ярощук <a.yaroshuk@aloha.org.ua> wrote:

Thanks for your answers. I will definitely try to use plugin « iterateurs ». According to description it is very useful tool.

I tried to use calculer_balise_dynamique for transforming SPIP-BONUX’s static tag TRI into dynamic, but had no good results. Using this tag is described here: http://www.spip-contrib.net/Utiliser-la-balise-TRI-et-le-crietre-tri-dans-les I wanted to modify this tag with possibility of changing sort order via clicking on table elements. My modifications worked only if I manually cleared cache between clicks. According to this I made a conclusion that problem is in SPIP caching. Eventually I found another decision. If someone is interested, I can describe it.

I’ll keep trying and looking for better solution for this « chaching » problem.

2011/10/19 Gilles VINCENT <gilles.vincent@gmail.com>

Hi,

can you give us an extract from your code that reproduces your problem ?
This is curious because #TRI and {tri} seems to correspond to your needs

Here is a code that works for me :

#CACHE{0}
<B_>
#PAGINATION

ID TITLE
#ID_ARTICLE#TITRE

Yes. Your solution works. But What if I want to change sort order via clicking ID. For example first click will give me articles with IDs 1,2,3…, second click will give 10, 9, 8…, third again 1,2,3… and so forth.
My current (may be not ideal) solution is:

[(#SET{defaut_tri,#ARRAY{

id_article,#ENV{sort_order,1},

titre,#ENV{sort_order,-1}

}})

<B_>
#PAGINATION

[(#ENV{sort_order}|=={1}|?{#SET{sort_order,-1},#SET{sort_order,1}})]

[(#TRI{id_article,ID,'',**#GET{sort_order}**})] [(#TRI{titre,TITLE,'',**#GET{sort_order}**})]
#ID_ARTICLE#TITRE

I added 4-th parameter to #TRI tag - sort order. I change it according to current sort_order.
In function balise_TRI_dist I added this code:

$_on = « false »;

$sort_order = interprete_argument_balise(4,$p);

if (!isset($sort_order)) $sort_order = « ‹  › »;

$_url = « parametre_url(parametre_url(self(),$_variable,$s?$_sens:$_champ), sort_order, $sort_order) »;

bofore string $p->code = « lien_ou_expose($_url,$_libelle,$_on ».($_class?« ,$_class »:«  »).« ) »;
Actually I reloaded this function within my plugin through creating function balise_TRI function without _dist.
What do you think about this? Am I on rigth way, or reinvent the wheel?

Thanks.

Hi,

there is another solution that doesn’t change anything in plugin BONUX : it’s based on the conditional loop that is created by this plugin : http://pastebin.com/skGTW2Ad

#CACHE{0}
<BOUCLE_c(CONDITION){si #ENV{sort,asc}|=={asc}}>
<B_asc>
#PAGINATION

ID TITLE
#ID_ARTICLE#TITRE
**** **** #PAGINATION
ID TITLE
#ID_ARTICLE#TITRE
****

But I agree with you that the order should be a parameter of the criteria {tri}
Maybe we should suggest this improvement to the mailing list spip-zone ?

.Gilles

On Wed, Oct 19, 2011 at 2:49 PM, Алексей Ярощук <a.yaroshuk@aloha.org.ua> wrote:

2011/10/19 Gilles VINCENT <gilles.vincent@gmail.com>

Hi,

can you give us an extract from your code that reproduces your problem ?
This is curious because #TRI and {tri} seems to correspond to your needs

Here is a code that works for me :

#CACHE{0}
<B_>
#PAGINATION

ID TITLE
#ID_ARTICLE#TITRE

Yes. Your solution works. But What if I want to change sort order via clicking ID. For example first click will give me articles with IDs 1,2,3…, second click will give 10, 9, 8…, third again 1,2,3… and so forth.
My current (may be not ideal) solution is:

[(#SET{defaut_tri,#ARRAY{

id_article,#ENV{sort_order,1},

titre,#ENV{sort_order,-1}

}})

<B_>
#PAGINATION

[(#ENV{sort_order}|=={1}|?{#SET{sort_order,-1},#SET{sort_order,1}})]

[(#TRI{id_article,ID,'',**#GET{sort_order}**})] [(#TRI{titre,TITLE,'',**#GET{sort_order}**})]
#ID_ARTICLE#TITRE

I added 4-th parameter to #TRI tag - sort order. I change it according to current sort_order.
In function balise_TRI_dist I added this code:

$_on = « false »;

$sort_order = interprete_argument_balise(4,$p);

if (!isset($sort_order)) $sort_order = « ‹  › »;

$_url = « parametre_url(parametre_url(self(),$_variable,$s?$_sens:$_champ), sort_order, $sort_order) »;

bofore string $p->code = « lien_ou_expose($_url,$_libelle,$_on ».($_class?« ,$_class »:«  »).« ) »;
Actually I reloaded this function within my plugin through creating function balise_TRI function without _dist.
What do you think about this? Am I on rigth way, or reinvent the wheel?

Thanks.

Yes this solution will work, but what about DRY (Dont Repeat Yourself) principle? Because of one condition we repeat all boucle! I used this method solving another issue, and I didn’t really like it.

I completly agree with you. I also think the sort order should be added to the tag #TRI. Your solution is the best.

On Wed, Oct 19, 2011 at 3:32 PM, Алексей Ярощук <a.yaroshuk@aloha.org.ua> wrote:

Yes this solution will work, but what about DRY (Dont Repeat Yourself) principle? Because of one condition we repeat all boucle! I used this method solving another issue, and I didn’t really like it.

Le 19/10/2011 16:29, Gilles VINCENT a écrit :

I completly agree with you. I also think the sort order should be added to the tag #TRI. Your solution is the best.

On Wed, Oct 19, 2011 at 3:32 PM, Алексей Ярощук <a.yaroshuk@aloha.org.ua
<mailto:a.yaroshuk@aloha.org.ua>> wrote:

    Yes this solution will work, but what about DRY (Dont Repeat Yourself) principle? Because of one condition we repeat
    all boucle! I used this method solving another issue, and I didn't really like it.

i'm not sure to get it all well, but it is possible to switch order using a parameter with inverse criterium :
{inverse #ENV{sensdutri}} avec les valeurs 0 ou 1.

Would that not fullfill the requested need ?

JLuc

Ah, this corresponds to a chapter that isn’t in the english translation :
http://www.spip.net/fr_article900.html#inverse

« Depuis SPIP 1.9, le critère inverse peut prendre en paramètre n’importe quelle balise pour varier dynamiquement le sens du tri. Par exemple, il est possible d’écrire : <BOUCLE_exemple(ARTICLES){par #ENV{tri}}{inverse #ENV{senstri}}>, ce qui permet de choisir la colonne de tri et le sens du tri par l’url (&senstri=1 ou &senstri=0) »

On Wed, Oct 19, 2011 at 6:39 PM, JLuc <jluc@no-log.org> wrote:

Le 19/10/2011 16:29, Gilles VINCENT a écrit :

I completly agree with you. I also think the sort order should be added to the tag #TRI. Your solution is the best.

On Wed, Oct 19, 2011 at 3:32 PM, Алексей Ярощук <a.yaroshuk@aloha.org.ua

mailto:[a.yaroshuk@aloha.org.ua](mailto:a.yaroshuk@aloha.org.ua)> wrote:

Yes this solution will work, but what about DRY (Dont Repeat Yourself) principle? Because of one condition we repeat
all boucle! I used this method solving another issue, and I didn’t really like it.

i’m not sure to get it all well, but it is possible to switch order using a parameter with inverse criterium :
{inverse #ENV{sensdutri}} avec les valeurs 0 ou 1.

Would that not fullfill the requested need ?

JLuc


spip-en@rezo.net - http://listes.rezo.net/mailman/listinfo/spip-en

Yes, this solution works and I think it really makes sense. But whatever, I think it would be great if this tool was included in SPIP-BONUX.

2011/10/19 Gilles VINCENT <gilles.vincent@gmail.com>

Ah, this corresponds to a chapter that isn’t in the english translation :
http://www.spip.net/fr_article900.html#inverse

« Depuis SPIP 1.9, le critère inverse peut prendre en paramètre n’importe quelle balise pour varier dynamiquement le sens du tri. Par exemple, il est possible d’écrire : <BOUCLE_exemple(ARTICLES){par #ENV{tri}}{inverse #ENV{senstri}}>, ce qui permet de choisir la colonne de tri et le sens du tri par l’url (&senstri=1 ou &senstri=0) »

On Wed, Oct 19, 2011 at 6:39 PM, JLuc <jluc@no-log.org> wrote:

Le 19/10/2011 16:29, Gilles VINCENT a écrit :

I completly agree with you. I also think the sort order should be added to the tag #TRI. Your solution is the best.

On Wed, Oct 19, 2011 at 3:32 PM, Алексей Ярощук <a.yaroshuk@aloha.org.ua

mailto:[a.yaroshuk@aloha.org.ua](mailto:a.yaroshuk@aloha.org.ua)> wrote:

Yes this solution will work, but what about DRY (Dont Repeat Yourself) principle? Because of one condition we repeat
all boucle! I used this method solving another issue, and I didn’t really like it.

i’m not sure to get it all well, but it is possible to switch order using a parameter with inverse criterium :
{inverse #ENV{sensdutri}} avec les valeurs 0 ou 1.

Would that not fullfill the requested need ?

JLuc


spip-en@rezo.net - http://listes.rezo.net/mailman/listinfo/spip-en


spip-en@rezo.net - http://listes.rezo.net/mailman/listinfo/spip-en