Page MenuHomePhabricator

API has 2 methods of setting cache mode
Closed, DeclinedPublic

Description

The api seem to have both:

$this->getMain()->setCacheMode( 'anon-public-user-private' );

and also

public function getCacheMode( $params ) {

		return 'anon-public-user-private';

}

I don't really see any need why we need both (though, if someone has a compelling enough reason, this can be WONTFIX'd or something)


Version: unspecified
Severity: normal

Details

Reference
bz40869

Event Timeline

bzimport raised the priority of this task from to Low.Nov 22 2014, 1:06 AM
bzimport set Reference to bz40869.
bzimport added a subscriber: Unknown Object (MLST).

Is it at least the case that all core modules use one and not the other? Or is the usage mixed? Maybe use cases would shed more light on why both of these exist.

In core:

  • 4 usages of $this->getMain()->setCacheMode()
  • 34 declarations of function getCacheMode( $params ) {}

Extensions:

  • 6 usages of $this->getMain()->setCacheMode()
  • 19 declarations of function getCacheMode( $params ) {}

They do seem to be used somewhat interchangeably..

Krinkle set Security to None.
Krinkle removed a subscriber: Unknown Object (MLST).
Anomie claimed this task.
Anomie subscribed.

setCacheMode() is the direct way to set the cache mode, overriding the default "private" when the response isn't really private or ephemeral.

getCacheMode() is only implemented by query submodules (and ApiPageSet): ApiQuery uses this method to fetch the cache requirements of all the used submodules to determine the final value to pass to setCacheMode().

Other action modules that don't already use "private" and that use ApiPageSet with generators should be calling its getCacheMode() to determine if they need a more restrictive mode. All such modules currently in Gerrit are using the default "private", though, so none of them actually need this call.