Difference between revisions of "Cache API"

From FollowTheScore
Jump to: navigation, search
 
(15 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
This is a development page for the Cache API that we are currently implementing. Talk to [[User_talk:EmuWikiAdmin-|EmuWikiAdmin-]] for more information.
 
This is a development page for the Cache API that we are currently implementing. Talk to [[User_talk:EmuWikiAdmin-|EmuWikiAdmin-]] for more information.
  
 +
'''Manual'''
 
----
 
----
Ok the dummy was implemented here : http://www.emuwiki.com/testinstall/extensions/CacheAPI.txt
 
[[User:EmuWikiAdmin-|EmuWikiAdmin-]] 01:04, 28 June 2009 (UTC)
 
  
 +
We have a somewhat working version here : http://www.emuwiki.com/testinstall/extensions/CacheAPI_current.txt
 +
 +
 +
Updated : [[User:EmuWikiAdmin-|EmuWikiAdmin-]] 05:57, 1 July 2009 (UTC)
 +
 +
 +
'''Installing'''
 
----
 
----
I also have a somewhat working version here : http://www.emuwiki.com/testinstall/extensions/CacheAPI_current.txt
 
  
For now, all it takes to make it work is to rename to php, include in Local Settings, and execute the following SQL command :
+
For now this SQL command needs to be executed manually before installing :
  
 
<pre>
 
<pre>
 
  CREATE TABLE IF NOT EXISTS `cacheapi` (
 
  CREATE TABLE IF NOT EXISTS `cacheapi` (
 +
`dependencies` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
 +
`firstdep` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
 +
`types` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
 +
`firsttype` SMALLINT NOT NULL ,
 
`page_ids` INT(10) NOT NULL ,
 
`page_ids` INT(10) NOT NULL ,
`dependencies` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
+
INDEX ( `firstdep`(30) ) ,
`first` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
+
INDEX ( `firsttype` ) ,
`type` INT(10) NOT NULL ,
+
INDEX ( `page_ids` )
INDEX ( `page_ids` , `dependencies`(40) , `first`(40) , `type` )
 
 
) ENGINE = MYISAM  
 
) ENGINE = MYISAM  
 
</pre>
 
</pre>
  
This version implements the 3 types of dependencies (category, template, linksto), but no time dependency yet.
 
  
For now, only saving (editing, creating) an article will outdate the cache, not doing other things such as deleting or moving articles (to come).
+
'''Removing dependencies'''
 +
----
  
Updated June 27th 21:00
+
To remove all dependencies of a page, use CacheAPI::remDependencies ( $idOfThePage ).
  
[[User:EmuWikiAdmin-|EmuWikiAdmin-]] 01:04, 28 June 2009 (UTC)
 
  
 +
 +
'''Adding dependencies'''
 
----
 
----
  
TODO :  
+
To add a dependency, use CacheAPI::addDependencies ( $pageid , $types, $conditions );
 +
 
 +
$types is an array that needs to be as long as the first dimension of the 2-dimensional array $conditions. Values in $types can be :
 +
 
 +
<pre>
 +
CACHETYPE_CATEGORY
 +
CACHETYPE_TEMPLATE
 +
CACHETYPE_LINKSTO
 +
CACHETYPE_NOTCATEGORY
 +
CACHETYPE_NOTTEMPLATE
 +
CACHETYPE_NOTLINKSTO
 +
CACHETYPE_LINKSFROM
 +
CACHETYPE_NAMESPACE
 +
CACHETYPE_NOTNAMESPACE
 +
CACHETYPE_OPENREFERENCES
 +
CACHETYPE_LINKSTOEXTERNAL
 +
CACHETYPE_IMAGEUSED
 +
CACHETYPE_IMAGECONTAINER
 +
CACHETYPE_TEMPLATESUSEDBY
 +
CACHETYPE_CREATEDBY
 +
CACHETYPE_NOTCREATEDBY
 +
CACHETYPE_MODIFIEDBY
 +
CACHETYPE_NOTMODIFIEDBY
 +
CACHETYPE_LASTMODIFIEDBY
 +
CACHETYPE_NOTLASTMODIFIEDBY
 +
CACHETYPE_TITLE
 +
CACHETYPE_TITLESHORTERTHAN
 +
CACHETYPE_TITLELONGERTHAN
 +
CACHETYPE_LASTREVISIONBEFORE
 +
CACHETYPE_FIRSTREVISIONSINCE
 +
CACHETYPE_ALLREVISIONBEFORE
 +
CACHETYPE_ALLREVISIONSINCE
 +
CACHETYPE_MAXREVISIONS
 +
CACHETYPE_MINREVISIONS
 +
CACHETYPE_ARTICLECATEGORY
 +
 
 +
CACHETYPE_ORCATEGORY
 +
CACHETYPE_ORTEMPLATE
 +
CACHETYPE_ORLINKSTO
 +
CACHETYPE_ORNOTCATEGORY
 +
CACHETYPE_ORNOTTEMPLATE
 +
CACHETYPE_ORNOTLINKSTO
 +
CACHETYPE_ORLINKSFROM
 +
CACHETYPE_ORNAMESPACE
 +
CACHETYPE_ORNOTNAMESPACE
 +
CACHETYPE_OROPENREFERENCES
 +
CACHETYPE_ORLINKSTOEXTERNAL
 +
CACHETYPE_ORIMAGEUSED
 +
CACHETYPE_ORIMAGECONTAINER
 +
CACHETYPE_ORTEMPLATESUSEDBY
 +
CACHETYPE_ORCREATEDBY
 +
CACHETYPE_ORNOTCREATEDBY
 +
CACHETYPE_ORMODIFIEDBY
 +
CACHETYPE_ORNOTMODIFIEDBY
 +
CACHETYPE_ORLASTMODIFIEDBY
 +
CACHETYPE_ORNOTLASTMODIFIEDBY
 +
CACHETYPE_ORTITLE
 +
CACHETYPE_ORTITLESHORTERTHAN
 +
CACHETYPE_ORTITLELONGERTHAN
 +
CACHETYPE_ORLASTREVISIONBEFORE
 +
CACHETYPE_ORFIRSTREVISIONSINCE
 +
CACHETYPE_ORALLREVISIONBEFORE
 +
CACHETYPE_ORALLREVISIONSINCE
 +
CACHETYPE_ORMAXREVISIONS
 +
CACHETYPE_ORMINREVISIONS
 +
CACHETYPE_ORARTICLECATEGORY
 +
</pre>
 +
 
 +
For now, only Categories are fully implemented for testing but the rest is implemented as dummy and should be fully ready very soon. To avoid performance issues, we will restrict the possible first types in your array. For example, a NOT should not be used as your first type, just as 2nd or more...
 +
 
 +
$condition is a bidimensional array of category names, template names, title names, etc...
 +
 
 +
 
 +
 
 +
'''Example'''
 +
----
 +
 
 +
'''Example with only ANDs'''
 +
 
 +
 
 +
Say we have a DPL invocation like this :
  
* Implement other types of dependencies (Namespace, linksfrom, etc...)
 
* Implement the NOTs (notcategory, notlinksto, etc...)
 
* Make a better system for deleation of dependencies (right now, the only thing you can do is delete ALL dependencies related to a page at once)
 
* Implement cache outdating when special events other than edit/create are performed (deletion, rename, etc...)
 
* If you need anything else, add it here.
 
  
== First Feedback ==
+
<pre>
Hello Jean-Francois,
+
{{#dpl:
 +
|allowcachedresults=yes
 +
|category = Test&Blablou&Papou
 +
|notcategory = Mimi
 +
|nottemplate = Stars
 +
|include            ={Test}:String
 +
|format              =,,,
 +
|secseparators      =,%PAGE%,
 +
}}
 +
</pre>
  
I decided to call your API immediately before executing my own SQL, that is near line 2418 in DPLMain.php.
+
Then the CacheAPI should be called with the following parameters :
I used the following code to call your interface:
 
  
 
<pre>
 
<pre>
 +
$types = array ( CACHETYPE_CATEGORY , CACHETYPE_NOTCATEGORY , CACHETYPE_NOTTEMPLATE );
  
// update dependencies to CacheAPI whenever the page containing the DPL query is edited
+
$conditions = array (
+
                    array ( 'Test' , 'Blablou' , 'Papou' ) ,
if ($wgRequest->getVal('action','view')=='submit') {
+
                    array ( 'Mimi' ) ,
CacheAPI::remDependencies ( $wgArticle->getID());
+
                    array ( 'Stars' )  
foreach ($aIncludeCategories as $categoryGroup) {
+
              );
foreach ($categoryGroup as $category) {
+
 
$title = Title::makeTitle(14, $category);
+
CacheAPI::addDependencies ( $pageid , $types, $conditions );
$catID = $title->getArticleID();
 
CacheAPI::addDependencies ( $wgArticle->getID(), 1, $catID, '');
 
// die ("adding to DEPENDENCIES: ".$title->getArticleID());
 
}
 
}
 
}
 
 
</pre>
 
</pre>
  
* you must add a "global $wgArticle;" somwehere above this code.
+
 
* Is it correct that you expect the pageID of the page containing the DPL statement as the first argument?
+
'''Example with ORs'''
* Would it make sense to add a second index to your table to spped up search when dependant articles are changed?
+
 
* What is the & separator good for? I have groups of OR-wired cats. All groups are AND-wired....
+
 
* I would like to use symbolic constants instead of pure numbers for the types (1,2,3)
+
Say we have a DPL invocation like this :
* I had to delete the final php delimiter at the end of your source code because there seems to be some invisible UTF code after it.
+
 
* I created a small article containing the following query:
 
  
 
<pre>
 
<pre>
        {{#time:Y-m-d h:i:s}}
+
{{#dpl:
        {{#dpl:
+
|allowcachedresults=yes
        | category = Test¦Fictitious country
+
|category = Test|Blablou
        }}
+
|notcategory = Mimi
 +
|nottemplate = Stars
 +
|include            ={Test}:String
 +
|format              =,,,
 +
|secseparators      =,%PAGE%,
 +
}}
 
</pre>
 
</pre>
  
* I used the following parameter in the LocalSettings.php (because this would be a typical configuration for a huge wiki I guess):
+
Then the CacheAPI should be called 2 times with the following parameters :
  ExtDynamicPageList::$respectParserCache = true;
 
* Instead of doing this I could have written in the DPL query
 
| allowcachedresults=true
 
* The #time statement is very useful - so you can see that the time does NOT change if you reload the query page multiple times.
 
* After editing the query page I saw two entries in the new table, correctly pointing to the two categories (Test , Fictitious country)
 
* Multiple reloading of the query page showed the same date/time each time (which is correct because the ParserCache is enabled)
 
* Then I modified [[Nigunda Test]] which is one of the articles occuring in the query result in a different browser window.
 
* I expected the cache now to be invalidated. So when I pressed F5 on the window with the query page I should have gotten a new time stamp - but this did not happen.
 
  
* I have no idea how the ParserCache works but the whole idea is:
+
<pre>
*# use the ParserCache - even for pages containing DPL queries (by default DPL switches the cache off so onbe must pay attention here)
+
$types = array ( CACHETYPE_CATEGORY , CACHETYPE_NOTCATEGORY , CACHETYPE_NOTTEMPLATE );
*# change a page contained in the result (regardless what kind of change, I assume at the moment)
 
*# refresh the DPL page
 
*# ... and watch that the DPL page is no longer delivered from cache but recalculated.
 
  
I think it is best if you set up a similar configuration (article names and cat names may differ) and then try to make the simple example with one or two categories work on your pc. If you have to change the lines in DPLMain.php which I used to call your API: go ahead and tell me what you have done.
+
$conditions = array (
 +
                    array ( 'Test' ) ,
 +
                    array ( 'Mimi' ) ,
 +
                    array ( 'Stars' )
 +
              );
  
 +
CacheAPI::addDependencies ( $pageid , $types, $conditions );
  
Happy testing!
 
  
Gero
+
$types = array ( CACHETYPE_CATEGORY , CACHETYPE_NOTCATEGORY , CACHETYPE_NOTTEMPLATE );
 +
 
 +
$conditions = array (
 +
                    array ( 'Blablou' ) ,
 +
                    array ( 'Mimi' ) ,
 +
                    array ( 'Stars' )
 +
              );
 +
 
 +
CacheAPI::addDependencies ( $pageid , $types, $conditions );
 +
</pre>
 +
 
 +
----
 +
TODO :
 +
 
 +
* Implement other types of dependencies (Namespace, linksfrom, etc...) - currently being done
 +
* Implement the NOTs (notcategory, notlinksto, etc...) - currently being done
 +
* Make a better system for deletion of dependencies (right now, the only thing you can do is delete ALL dependencies related to a page at once, this is not good for pages with multiple DPL invocations).
 +
* If you need anything else, add it here.
 +
----
 +
 
 +
Feedback and discussion moved [[Talk:Cache API|here]].

Latest revision as of 16:31, 1 August 2009

This is a development page for the Cache API that we are currently implementing. Talk to EmuWikiAdmin- for more information.

Manual


We have a somewhat working version here : http://www.emuwiki.com/testinstall/extensions/CacheAPI_current.txt


Updated : EmuWikiAdmin- 05:57, 1 July 2009 (UTC)


Installing


For now this SQL command needs to be executed manually before installing :

 CREATE TABLE IF NOT EXISTS `cacheapi` (
`dependencies` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
`firstdep` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
`types` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
`firsttype` SMALLINT NOT NULL ,
`page_ids` INT(10) NOT NULL ,
INDEX ( `firstdep`(30) ) ,
INDEX ( `firsttype` ) ,
INDEX ( `page_ids` )
) ENGINE = MYISAM 


Removing dependencies


To remove all dependencies of a page, use CacheAPI::remDependencies ( $idOfThePage ).


Adding dependencies


To add a dependency, use CacheAPI::addDependencies ( $pageid , $types, $conditions );

$types is an array that needs to be as long as the first dimension of the 2-dimensional array $conditions. Values in $types can be :

CACHETYPE_CATEGORY
CACHETYPE_TEMPLATE
CACHETYPE_LINKSTO
CACHETYPE_NOTCATEGORY
CACHETYPE_NOTTEMPLATE
CACHETYPE_NOTLINKSTO
CACHETYPE_LINKSFROM
CACHETYPE_NAMESPACE
CACHETYPE_NOTNAMESPACE
CACHETYPE_OPENREFERENCES
CACHETYPE_LINKSTOEXTERNAL
CACHETYPE_IMAGEUSED
CACHETYPE_IMAGECONTAINER
CACHETYPE_TEMPLATESUSEDBY
CACHETYPE_CREATEDBY
CACHETYPE_NOTCREATEDBY
CACHETYPE_MODIFIEDBY
CACHETYPE_NOTMODIFIEDBY
CACHETYPE_LASTMODIFIEDBY
CACHETYPE_NOTLASTMODIFIEDBY
CACHETYPE_TITLE
CACHETYPE_TITLESHORTERTHAN
CACHETYPE_TITLELONGERTHAN
CACHETYPE_LASTREVISIONBEFORE
CACHETYPE_FIRSTREVISIONSINCE
CACHETYPE_ALLREVISIONBEFORE
CACHETYPE_ALLREVISIONSINCE
CACHETYPE_MAXREVISIONS
CACHETYPE_MINREVISIONS
CACHETYPE_ARTICLECATEGORY

CACHETYPE_ORCATEGORY
CACHETYPE_ORTEMPLATE
CACHETYPE_ORLINKSTO
CACHETYPE_ORNOTCATEGORY
CACHETYPE_ORNOTTEMPLATE
CACHETYPE_ORNOTLINKSTO
CACHETYPE_ORLINKSFROM
CACHETYPE_ORNAMESPACE
CACHETYPE_ORNOTNAMESPACE
CACHETYPE_OROPENREFERENCES
CACHETYPE_ORLINKSTOEXTERNAL
CACHETYPE_ORIMAGEUSED
CACHETYPE_ORIMAGECONTAINER
CACHETYPE_ORTEMPLATESUSEDBY
CACHETYPE_ORCREATEDBY
CACHETYPE_ORNOTCREATEDBY
CACHETYPE_ORMODIFIEDBY
CACHETYPE_ORNOTMODIFIEDBY
CACHETYPE_ORLASTMODIFIEDBY
CACHETYPE_ORNOTLASTMODIFIEDBY
CACHETYPE_ORTITLE
CACHETYPE_ORTITLESHORTERTHAN
CACHETYPE_ORTITLELONGERTHAN
CACHETYPE_ORLASTREVISIONBEFORE
CACHETYPE_ORFIRSTREVISIONSINCE
CACHETYPE_ORALLREVISIONBEFORE
CACHETYPE_ORALLREVISIONSINCE
CACHETYPE_ORMAXREVISIONS
CACHETYPE_ORMINREVISIONS
CACHETYPE_ORARTICLECATEGORY

For now, only Categories are fully implemented for testing but the rest is implemented as dummy and should be fully ready very soon. To avoid performance issues, we will restrict the possible first types in your array. For example, a NOT should not be used as your first type, just as 2nd or more...

$condition is a bidimensional array of category names, template names, title names, etc...


Example


Example with only ANDs


Say we have a DPL invocation like this :


{{#dpl:
|allowcachedresults=yes
|category = Test&Blablou&Papou
|notcategory = Mimi
|nottemplate = Stars
|include             ={Test}:String
|format              =,,,
|secseparators       =,%PAGE%,
}}

Then the CacheAPI should be called with the following parameters :

$types = array ( CACHETYPE_CATEGORY , CACHETYPE_NOTCATEGORY , CACHETYPE_NOTTEMPLATE );

$conditions = array (
                    array ( 'Test' , 'Blablou' , 'Papou' ) ,
                    array ( 'Mimi' ) ,
                    array ( 'Stars' ) 
              );

CacheAPI::addDependencies ( $pageid , $types, $conditions );


Example with ORs


Say we have a DPL invocation like this :


{{#dpl:
|allowcachedresults=yes
|category = Test|Blablou
|notcategory = Mimi
|nottemplate = Stars
|include             ={Test}:String
|format              =,,,
|secseparators       =,%PAGE%,
}}

Then the CacheAPI should be called 2 times with the following parameters :

$types = array ( CACHETYPE_CATEGORY , CACHETYPE_NOTCATEGORY , CACHETYPE_NOTTEMPLATE );

$conditions = array (
                    array ( 'Test' ) ,
                    array ( 'Mimi' ) ,
                    array ( 'Stars' ) 
              );

CacheAPI::addDependencies ( $pageid , $types, $conditions );


$types = array ( CACHETYPE_CATEGORY , CACHETYPE_NOTCATEGORY , CACHETYPE_NOTTEMPLATE );

$conditions = array (
                    array ( 'Blablou' ) ,
                    array ( 'Mimi' ) ,
                    array ( 'Stars' ) 
              );

CacheAPI::addDependencies ( $pageid , $types, $conditions );

TODO :

  • Implement other types of dependencies (Namespace, linksfrom, etc...) - currently being done
  • Implement the NOTs (notcategory, notlinksto, etc...) - currently being done
  • Make a better system for deletion of dependencies (right now, the only thing you can do is delete ALL dependencies related to a page at once, this is not good for pages with multiple DPL invocations).
  • If you need anything else, add it here.

Feedback and discussion moved here.