Difference between revisions of "Cache API"

From FollowTheScore
Jump to: navigation, search
 
(19 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'''
 +
----
 +
 
 +
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 :
 +
 
 +
<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...
  
Updated June 27th 21:00
 
  
[[User:EmuWikiAdmin-|EmuWikiAdmin-]] 01:04, 28 June 2009 (UTC)
 
  
 +
'''Example'''
 
----
 
----
  
TODO :  
+
'''Example with only ANDs'''
 +
 
 +
 
 +
Say we have a DPL invocation like this :
 +
 
 +
 
 +
<pre>
 +
{{#dpl:
 +
|allowcachedresults=yes
 +
|category = Test&Blablou&Papou
 +
|notcategory = Mimi
 +
|nottemplate = Stars
 +
|include            ={Test}:String
 +
|format              =,,,
 +
|secseparators      =,%PAGE%,
 +
}}
 +
</pre>
 +
 
 +
Then the CacheAPI should be called with the following parameters :
 +
 
 +
<pre>
 +
$types = array ( CACHETYPE_CATEGORY , CACHETYPE_NOTCATEGORY , CACHETYPE_NOTTEMPLATE );
 +
 
 +
$conditions = array (
 +
                    array ( 'Test' , 'Blablou' , 'Papou' ) ,
 +
                    array ( 'Mimi' ) ,
 +
                    array ( 'Stars' )
 +
              );
 +
 
 +
CacheAPI::addDependencies ( $pageid , $types, $conditions );
 +
</pre>
 +
 
 +
 
 +
'''Example with ORs'''
 +
 
 +
 
 +
Say we have a DPL invocation like this :
 +
 
 +
 
 +
<pre>
 +
{{#dpl:
 +
|allowcachedresults=yes
 +
|category = Test|Blablou
 +
|notcategory = Mimi
 +
|nottemplate = Stars
 +
|include            ={Test}:String
 +
|format              =,,,
 +
|secseparators      =,%PAGE%,
 +
}}
 +
</pre>
 +
 
 +
Then the CacheAPI should be called 2 times with the following parameters :
 +
 
 +
<pre>
 +
$types = array ( CACHETYPE_CATEGORY , CACHETYPE_NOTCATEGORY , CACHETYPE_NOTTEMPLATE );
 +
 
 +
$conditions = array (
 +
                    array ( 'Test' ) ,
 +
                    array ( 'Mimi' ) ,
 +
                    array ( 'Stars' )
 +
              );
  
* Implement other types of dependencies (Namespace, linksfrom, etc...)
+
CacheAPI::addDependencies ( $pageid , $types, $conditions );
* 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 ==
 
Hello Jean-Francois,
 
  
I decided to call your API immediately before executing my own SQL, that is near line 2418 in DPLMain.php.
+
$types = array ( CACHETYPE_CATEGORY , CACHETYPE_NOTCATEGORY , CACHETYPE_NOTTEMPLATE );
  
// add dependencies to CacheAPI
+
$conditions = array (
+
                    array ( 'Blablou' ) ,
foreach ($aIncludeCategories as $categoryGroup) {
+
                    array ( 'Mimi' ) ,
foreach ($categoryGroup as $category) {
+
                    array ( 'Stars' )
$title = Title::makeTitle(14, $category);
+
              );
$catID = $title->getArticleID();
 
CacheAPI::addDependencies ( $wgArticle->getID(), 1, $catID, '');  
 
}
 
}
 
  
* Is it correct tha you expect the pageID of the page containing the DPL statement as the first argument?
+
CacheAPI::addDependencies ( $pageid , $types, $conditions );
* I noticed that multiple edits of my article lead to multiple redundant entries in your cache table. I think you need to define an index.
+
</pre>
* What happens if the DPL statement changes? Let us say if forst used cat A but now it uses cat B as a search criterion. Will you delete the old inmformation in your table?
 
* I would like to have symbolic constants instead of pure numbers for the types (1,2,3)
 
* I had to delete the final php delimiter because there seems to be some invisible UTF code after it.
 
* I created a small article containing the following query:
 
{{#time:Y-m-d h:i:s}}
 
{{#dpl:
 
| category = Fictitious country
 
}}
 
* I used the following parameter in the LocalSettings.php:
 
  ExtDynamicPageList::$respectParserCache = true;
 
* Instead of doing this I could have swritten in the DPL query
 
| allowcachedresults=true
 
* I saved the query and then modified [[Nigunda Test]] which is one of the articles in the query result in a different browser window.
 
* I expected the cache to be invalidated. So when I pressed F5 on the windown with teh query page I should have gotten a new time stamp - but this did not happen.
 
* Instead there was much resource consumption on the PC before the page was shown again.
 
* Afterwards the table contained lots of entries (ca. 40)
 
  
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 category work on your pc. If you have to change the few lines in DPLMain.php: go ahead and tell me what you have done.
+
----
 +
TODO :  
  
Happy testing!
+
* 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.
 +
----
  
Gero
+
Feedback and discussion moved [[Talk:Cache API|here]].

Latest revision as of 15: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.