Query Cache
* added to api cache response get published event and event feedback response. * updated cache middleware to allow cache lifetime to be configurable. Change-Id: I9dccb7b27e83cffed6f5ae2fb60623ab9bad9f24
This commit is contained in:
parent
bb20ca1388
commit
362e897511
@ -43,14 +43,15 @@ final class CacheMiddleware
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle an incoming request.
|
* @param $request
|
||||||
* @param \Illuminate\Http\Request $request
|
* @param Closure $next
|
||||||
* @param \Closure $next
|
* @param $cache_lifetime
|
||||||
* @return mixed
|
* @return JsonResponse
|
||||||
*/
|
*/
|
||||||
public function handle($request, Closure $next)
|
public function handle($request, Closure $next, $cache_lifetime)
|
||||||
{
|
{
|
||||||
Log::debug('cache middleware invoked ...');
|
Log::debug('cache middleware invoked ...');
|
||||||
|
$cache_lifetime = intval($cache_lifetime);
|
||||||
if ($request->getMethod() !== 'GET')
|
if ($request->getMethod() !== 'GET')
|
||||||
{
|
{
|
||||||
// short circuit
|
// short circuit
|
||||||
@ -72,8 +73,6 @@ final class CacheMiddleware
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$cache_lifetime = intval(Config::get('server.response_cache_lifetime', 300));
|
|
||||||
|
|
||||||
if (str_contains($request->getPathInfo(), '/me'))
|
if (str_contains($request->getPathInfo(), '/me'))
|
||||||
{
|
{
|
||||||
$key .= ':' . $this->context->getCurrentUserExternalId();
|
$key .= ':' . $this->context->getCurrentUserExternalId();
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Config;
|
||||||
|
|
||||||
//OAuth2 Protected API
|
//OAuth2 Protected API
|
||||||
Route::group(array(
|
Route::group(array(
|
||||||
'namespace' => 'App\Http\Controllers',
|
'namespace' => 'App\Http\Controllers',
|
||||||
@ -49,7 +51,7 @@ Route::group(array(
|
|||||||
|
|
||||||
Route::group(array('prefix' => '{id}'), function () {
|
Route::group(array('prefix' => '{id}'), function () {
|
||||||
|
|
||||||
Route::get('', [ 'middleware' => 'cache', 'uses' => 'OAuth2SummitApiController@getSummit'])->where('id', 'current|[0-9]+');
|
Route::get('', [ 'middleware' => 'cache:'.Config::get('cache_api_response.get_summit_response_lifetime', 300), 'uses' => 'OAuth2SummitApiController@getSummit'])->where('id', 'current|[0-9]+');
|
||||||
|
|
||||||
Route::get('entity-events', 'OAuth2SummitApiController@getSummitEntityEvents');
|
Route::get('entity-events', 'OAuth2SummitApiController@getSummitEntityEvents');
|
||||||
|
|
||||||
@ -99,13 +101,13 @@ Route::group(array(
|
|||||||
Route::group(array('prefix' => '{event_id}'), function () {
|
Route::group(array('prefix' => '{event_id}'), function () {
|
||||||
|
|
||||||
Route::get('', 'OAuth2SummitEventsApiController@getEvent');
|
Route::get('', 'OAuth2SummitEventsApiController@getEvent');
|
||||||
Route::get('/published', 'OAuth2SummitEventsApiController@getScheduledEvent');
|
Route::get('/published', [ 'middleware' => 'cache:'.Config::get('cache_api_response.get_published_event_response_lifetime', 300), 'uses' => 'OAuth2SummitEventsApiController@getScheduledEvent']);
|
||||||
Route::put('', [ 'middleware' => 'auth.user:administrators', 'uses' => 'OAuth2SummitEventsApiController@updateEvent' ]);
|
Route::put('', [ 'middleware' => 'auth.user:administrators', 'uses' => 'OAuth2SummitEventsApiController@updateEvent' ]);
|
||||||
Route::delete('', [ 'middleware' => 'auth.user:administrators', 'uses' => 'OAuth2SummitEventsApiController@deleteEvent' ]);
|
Route::delete('', [ 'middleware' => 'auth.user:administrators', 'uses' => 'OAuth2SummitEventsApiController@deleteEvent' ]);
|
||||||
Route::put('/publish', [ 'middleware' => 'auth.user:administrators', 'uses' => 'OAuth2SummitEventsApiController@publishEvent']);
|
Route::put('/publish', [ 'middleware' => 'auth.user:administrators', 'uses' => 'OAuth2SummitEventsApiController@publishEvent']);
|
||||||
Route::delete('/publish', [ 'middleware' => 'auth.user:administrators', 'uses' => 'OAuth2SummitEventsApiController@unPublishEvent']);
|
Route::delete('/publish', [ 'middleware' => 'auth.user:administrators', 'uses' => 'OAuth2SummitEventsApiController@unPublishEvent']);
|
||||||
Route::post('/feedback', 'OAuth2SummitEventsApiController@addEventFeedback');
|
Route::post('/feedback', 'OAuth2SummitEventsApiController@addEventFeedback');
|
||||||
Route::get('/feedback/{attendee_id?}', 'OAuth2SummitEventsApiController@getEventFeedback')->where('attendee_id', 'me|[0-9]+');
|
Route::get('/feedback/{attendee_id?}', ['middleware' => 'cache:'.Config::get('cache_api_response.get_event_feedback_response_lifetime', 300), 'uses' => 'OAuth2SummitEventsApiController@getEventFeedback'] )->where('attendee_id', 'me|[0-9]+');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -375,7 +375,7 @@ class Summit extends SilverstripeBaseModel
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\ManyToOne(targetEntity="models\main\File", fetch="EAGER")
|
* @ORM\ManyToOne(targetEntity="models\main\File")
|
||||||
* @ORM\JoinColumn(name="LogoID", referencedColumnName="ID")
|
* @ORM\JoinColumn(name="LogoID", referencedColumnName="ID")
|
||||||
* @var File
|
* @var File
|
||||||
*/
|
*/
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
<?php namespace repositories\summit;
|
<?php namespace repositories\summit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copyright 2016 OpenStack Foundation
|
* Copyright 2016 OpenStack Foundation
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
@ -12,15 +13,9 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
**/
|
**/
|
||||||
|
|
||||||
use Doctrine\ORM\Tools\Pagination\Paginator;
|
|
||||||
use Doctrine\ORM\Query\Expr\Join;
|
|
||||||
use models\summit\ISummitRepository;
|
use models\summit\ISummitRepository;
|
||||||
use models\summit\Summit;
|
use models\summit\Summit;
|
||||||
use repositories\SilverStripeDoctrineRepository;
|
use repositories\SilverStripeDoctrineRepository;
|
||||||
use utils\DoctrineJoinFilterMapping;
|
|
||||||
use utils\Filter;
|
|
||||||
use utils\PagingInfo;
|
|
||||||
use utils\PagingResponse;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class DoctrineSummitRepository
|
* Class DoctrineSummitRepository
|
||||||
@ -35,16 +30,16 @@ final class DoctrineSummitRepository extends SilverStripeDoctrineRepository impl
|
|||||||
*/
|
*/
|
||||||
public function getCurrent()
|
public function getCurrent()
|
||||||
{
|
{
|
||||||
$res = $this->getEntityManager()->createQueryBuilder()
|
$res = $this->getEntityManager()->createQueryBuilder()
|
||||||
->select("s")
|
->select("s")
|
||||||
->from(\models\summit\Summit::class, "s")
|
->from(\models\summit\Summit::class, "s")
|
||||||
->where('s.active = 1')
|
->where('s.active = 1')
|
||||||
->orderBy('s.begin_date','DESC')
|
->orderBy('s.begin_date', 'DESC')
|
||||||
->setCacheable(true)
|
|
||||||
->setCacheRegion('current_summit_region')
|
|
||||||
->getQuery()
|
->getQuery()
|
||||||
|
->setCacheable(true)
|
||||||
|
->setCacheRegion("summit_region")
|
||||||
->getResult();
|
->getResult();
|
||||||
if(count($res) == 0) return null;
|
if (count($res) == 0) return null;
|
||||||
return $res[0];
|
return $res[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
19
config/cache_api_response.php
Normal file
19
config/cache_api_response.php
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Copyright 2016 OpenStack Foundation
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
**/
|
||||||
|
|
||||||
|
return [
|
||||||
|
'get_summit_response_lifetime' => env('CACHE_API_RESPONSE_GET_SUMMIT_LIFETIME', 300),
|
||||||
|
'get_event_feedback_response_lifetime' => env('CACHE_API_RESPONSE_GET_EVENT_FEEDBACK_LIFETIME', 300),
|
||||||
|
'get_published_event_response_lifetime' => env('CACHE_API_RESPONSE_GET_PUBLISHED_EVENT_LIFETIME', 300),
|
||||||
|
];
|
Loading…
x
Reference in New Issue
Block a user