Skip to content

Commit

Permalink
Merge branch 'master' of github.com:caprowsky/si8
Browse files Browse the repository at this point in the history
  • Loading branch information
arrubiu committed Oct 17, 2017
2 parents 7dea06b + f29d62a commit 98fed48
Show file tree
Hide file tree
Showing 38 changed files with 7,254 additions and 0 deletions.
339 changes: 339 additions & 0 deletions modules/contrib/adv_varnish/LICENSE.txt

Large diffs are not rendered by default.

51 changes: 51 additions & 0 deletions modules/contrib/adv_varnish/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
DESCRIPTION:
This module provide integration with Varnish reverse
proxy server for Drupal 8.
Main feature of this module is
providing support of varnish
caching for authenticated users.

MAIN FEATURES:
Varnish support out of the box.
All you need is to install this
module use default.vcl from
this module and fill connection
settings for varnish terminal.

Cache for anonymous users.
Just set desired TTL in varnish
settings and it will works,
cache invalidation will happens
automatically and depends on new
Drupal 8 cache system with tags support.

Cache for authenticated users.
The same as for anonymous users
just fill the TTL and Varnish will
start to cache pages for authenticated
users based on PER ROLE option. We all
knows that page for authenticated
users can contain user-specific
content and we care about this. For
each user-specific block you can
choose to use ESI cache on PER-ROLE
or PER-USER basis so each user will
get proper content on the page.

Per Entity Cache settings.
You can select TTL on per entity (bundle)
settings. This module supports basic
entity types out of the box (node and
taxonomy terms) but you can easily add
support for any custom entity type all
you need is to create small plugin and
we will care of all other things for you.

Cache invalidation.
We use tags to control each page state,
so if any entity which presents on page
would be changed in Drupal, cache in
Varnish would be invalidate immediately.
Module support Drupal 8 cache system and
use all available cache metadata so you can
easy add required tags for any page that you want.
28 changes: 28 additions & 0 deletions modules/contrib/adv_varnish/adv_varnish.api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

/**
* @file
* Contains adv_varnish.api.php.
*/

/**
* Result provider for adv_esi element.
*
* @param string $data
* Data_type, that was defined in the cv_esi element.
* @param array $params
* Params, that was defined in the cv_esi element.
*
* @return array
* Render Array.
*
* @see \Drupal\adv_varnish\Controller\VarnishAdvEsiController::esi()
*/
function hook_esi_adv_varnish($data, array $params) {
if ($data == 'user-name') {
return [
'#markup' => \Drupal::currentUser()->getAccountName(),
];
}
return NULL;
}
12 changes: 12 additions & 0 deletions modules/contrib/adv_varnish/adv_varnish.info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Adv Varnish
type: module
description: Advanced Varnish Integration
# core: 8.x
package: Cache
configure: adv_varnish.settings

# Information added by Drupal.org packaging script on 2017-09-11
version: '8.x-2.0'
core: '8.x'
project: 'adv_varnish'
datestamp: 1505162945
5 changes: 5 additions & 0 deletions modules/contrib/adv_varnish/adv_varnish.links.menu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
adv_varnish.settings:
title: 'Adv Varnish'
route_name: adv_varnish.settings
parent: system.performance_settings
description: 'Manage Adv Varnish cache configuration'
13 changes: 13 additions & 0 deletions modules/contrib/adv_varnish/adv_varnish.links.task.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
adv_varnish.collection:
title: 'COM Varnish Settings'
route_name: adv_varnish.settings
base_route: system.admin_config_development
adv_varnish.config_form:
title: 'COM Varnish Settings'
route_name: adv_varnish.settings
parent_id: adv_varnish.collection
adv_varnish.purge_form:
title: 'Varnish Purge'
route_name: adv_varnish.purge
parent_id: adv_varnish.collection
weight: 3
76 changes: 76 additions & 0 deletions modules/contrib/adv_varnish/adv_varnish.module
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

/**
* @file
* Contains adv_varnish.module..
*/

/**
* Implements hook_toolbar_alter().
*/
function adv_varnish_toolbar_alter(&$items) {
// Alter toolbar menu, due to possible varnish cache issues.
// Update user tab name.
$items['user']['tab']['#title'] = t('My account');
}

/**
* Implements hook_hook_info().
*/
function adv_varnish_hook_info() {
$hooks['esi_adv_varnish'] = [
'group' => 'adv_varnish',
];
return $hooks;
}

/**
* ESI use.
*
* @return bool
* true/false.
*/
function adv_varnish_is_esi() {
$esi = &drupal_static(__FUNCTION__);
if (isset($esi['is_esi'])) {
return $esi['is_esi'];
}
$esi = [];
$general = \Drupal::config('adv_varnish.settings')->get('general');
$esi['is_esi'] = \Drupal::currentUser()->id() == '1' ? FALSE : !empty($general['esi']);
return $esi['is_esi'];
}

/**
* Implements hook_views_pre_render().
*/
function adv_varnish_views_pre_render($view) {
// Create static dom_id for views.
// In case we load view with ESI && AJAX.
if ($view->ajaxEnabled() && isset($view->element['#attached']['drupalSettings']['views']['ajaxViews'])) {
$ajax_view = $view->element['#attached']['drupalSettings']['views']['ajaxViews'];
$new_ajax_views = [];
foreach ($ajax_view as $settings) {
$view_dom_id = hash('sha256', implode('__', [$settings['view_name'], $settings['view_display_id']]));
$settings['view_dom_id'] = $view_dom_id;
$new_ajax_views['views_dom_id:' . $view_dom_id] = $settings;
$view->dom_id = $view_dom_id;
}
$view->element['#attached']['drupalSettings']['views']['ajaxViews'] = $new_ajax_views;
}

return $view;
}

/**
* Implements hook_module_implements_alter().
*/
function adv_varnish_module_implements_alter(&$implementations, $hook) {
// Reorder implements.
$module = 'adv_varnish';
if ($hook == 'views_pre_render' && isset($implementations[$module])) {
$group = $implementations[$module];
unset($implementations[$module]);
$implementations[$module] = $group;
}
}
8 changes: 8 additions & 0 deletions modules/contrib/adv_varnish/adv_varnish.permissions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
bypass adv varnish cache:
title: 'Bypass Varnish'
description: 'Varnish will not be used for users with this permission set.'
restrict access: TRUE
configure adv varnish settings:
title: 'Configure Adv Varnish settings'
description: 'This permission allow access to varnish configuration page.'
restrict access: TRUE
27 changes: 27 additions & 0 deletions modules/contrib/adv_varnish/adv_varnish.routing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
adv_varnish.settings:
path: '/admin/config/development/adv_varnish_config'
defaults:
_form: '\Drupal\adv_varnish\Form\VarnishAdvCacheSettingsForm'
_title: 'Adv Varnish Settings'
options:
_admin_route: TRUE
requirements:
_permission: 'configure com varnish settings'
adv_varnish.purge:
path: '/admin/config/development/adv_varnish/purge'
defaults:
_form: '\Drupal\adv_varnish\Form\VarnishAdvCachePurgeForm'
_title: 'Adv Varnish Purge'
options:
_admin_route: TRUE
requirements:
_permission: 'configure advanced varnish cache'
adv_varnish.esi:
path: '/adv-varnish/esi/{type}'
defaults:
_controller: '\Drupal\adv_varnish\Controller\VarnishAdvEsiController::esi'
requirements:
# PUBLIC callback for Varnish ESI.
_access: 'TRUE'
options:
no_cache: 'TRUE'
30 changes: 30 additions & 0 deletions modules/contrib/adv_varnish/adv_varnish.services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
parameters:
channel: adv_varnish

services:
adv_varnish.event_subscriber:
class: Drupal\adv_varnish\EventSubscriber\AdvCacheableResponseSubscriber
arguments: ['@language_manager', '@config.factory', '@page_cache_request_policy', '@page_cache_response_policy', '@cache_contexts_manager', '@adv_varnish.controller', '%http.response.debug_cacheability_headers%']
tags:
- {name: event_subscriber}

adv_varnish.handler:
class: Drupal\adv_varnish\Varnish
arguments: ['@config.factory', '@adv_varnish.logger', '@current_user']

adv_varnish.controller:
class: Drupal\adv_varnish\Controller\VarnishAdvController
arguments: ['@adv_varnish.handler', '@request_stack', '@current_user']

adv_varnish.logger:
class: Drupal\Core\Logger\LoggerChannel
factory_service: logger.factory
factory_method: get
arguments: ['%channel%']

cache_tags.invalidator.adv_varnish:
class: Drupal\adv_varnish\Cache\VarnishAdvCacheTagsInvalidator
properties:
varnishHandler: "@adv_varnish.handler"
tags:
- { name: cache_tags_invalidator}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Drupal\adv_varnish\Cache;

use Drupal\Core\Cache\CacheTagsInvalidatorInterface;

/**
* Class AdvancedVarnishCacheTagsInvalidator.
*/
class VarnishAdvCacheTagsInvalidator implements CacheTagsInvalidatorInterface {

/**
* Stores the state storage service.
*
* @var \Drupal\adv_varnish\VarnishInterface
*/
public $varnishHandler;

/**
* Marks cache items with any of the specified tags as invalid.
*
* @param string[] $tags
* The list of tags for which to invalidate cache items.
*/
public function invalidateTags(array $tags) {
$this->varnishHandler->purgeTags($tags);
}

}
Loading

0 comments on commit 98fed48

Please sign in to comment.