Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
apc
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
apc
Commits
81bd15a3
Commit
81bd15a3
authored
6 months ago
by
Alberto Paderno
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3469662
: Document the usage of $conf[cache_prefix] and $conf[apc_cache_prefix]
parent
ac755b59
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!70
Issue #3469662: Document the usage of $conf[cache_prefix] and $conf[apc_cache_prefix]
Pipeline
#261573
passed
6 months ago
Stage: build
Stage: validate
Stage: test
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
README.md
+116
-56
116 additions, 56 deletions
README.md
with
116 additions
and
56 deletions
README.md
+
116
−
56
View file @
81bd15a3
# Alternative PHP Cache
The Alternative PHP Cache module integrates the APCu extension with Drupal,
either as cache backend (already implemented) or as lock backend (still to
implement).
## Table of contents
-
Requirements
-
Installation
-
Configuration
-
Maintainers
## Requirements
This module requires no modules outside of Drupal core.
It requires the
[
APCu
](
https://www.php.net/manual/en/book.apcu.php
)
extension
(5.0.0 or higher) and PHP 5.6 or higher.
## Installation
### Step 1
Enable the module and verify the status page (/admin/reports/status) shows
the APCu extension has been loaded.
### Step 2
Choose whenever you want the APC extension for all the cache bins used from
Drupal or just for some cache bins.
APCu normally has a limited memory available (32M) and should be used to cache
the entries which are mostly used, since it is the cache closest (and maybe
fastest) to PHP. When the memory allocated by APCu is big enough to cache the
entire Drupal cache, you can follow
**Step 2b**
; otherwise you should follow
**Step 2a**
.
#### Step 2a
Add the following lines to your settings.php file
```
php
/**
* APC cache settings.
*/
$conf
[
'cache_backends'
][]
=
'sites/all/modules/apc/drupal_apc_cache.inc'
;
$conf
[
'cache_class_cache'
]
=
'DrupalAPCCache'
;
$conf
[
'cache_class_cache_bootstrap'
]
=
'DrupalAPCCache'
;
// Uncomment the following line to enable debugging.
// $conf['apc_show_debug'] = TRUE;
```
#### Step 2b
Add the following lines to your settings.php file.
```
php
/**
* APC cache settings.
*/
$conf
[
'cache_backends'
][]
=
'sites/all/modules/apc/drupal_apc_cache.inc'
;
$conf
[
'cache_default_class'
]
=
'DrupalAPCCache'
;
// The 'cache_form' bin must be assigned to non-volatile storage.
$conf
[
'cache_class_cache_form'
]
=
'DrupalDatabaseCache'
;
// Uncomment the following line to enable debugging.
// $conf['apc_show_debug'] = TRUE;
```
### Step 3
Visit your site and verify it still works.
### Step 4 (optional)
When
`DrupalAPCCache`
is used for the
*cache_page*
bin, the following lines
can be added to the settings.php file used for the site.
```
php
$conf
[
'page_cache_without_database'
]
=
TRUE
;
$conf
[
'page_cache_invoke_hooks'
]
=
FALSE
;
```
Install as you would normally install a contributed Drupal module. For further
information, see
[
Installing Drupal Modules
](
https://www.drupal.org/docs/extending-drupal/installing-drupal-modules
)
.
## Configuration
The module has no menu or modifiable settings.
Most of the configuration values are stored in the settings.php file. At least
the following line must be added in the settings.php file to use this module as
cache backend. (Correct the path if necessary.)
```
php
$conf
[
'cache_backends'
][]
=
'sites/all/modules/apc/drupal_apc_cache.inc'
;
```
Then lines like the following ones must be added for each cache bin to store on
APCu.
```
php
$conf
[
'cache_class_cache'
]
=
'DrupalApcCache'
;
$conf
[
'cache_class_cache_bootstrap'
]
=
'DrupalApcCache'
;
```
What follows
`cache_class_`
is the name of the cache bin. (In the given example,
the cache bins are
*cache*
and
*cache_bootstrap*
.)
APCu normally has a limited memory available (32M) and should be used to cache
the entries which are mostly used, since it is the cache closest to PHP (and
maybe the fastest one).
When the memory allocated by APCu is big enough to cache the entire Drupal
cache, instead of setting each single cache bin, you can use the following line,
which sets APCu as default backend for all the cache bins.
```
php
$conf
[
'cache_default_class'
]
=
'DrupalApcCache'
;
```
When
`DrupalAPCCache`
is used for the
*cache_page*
bin, the following lines can
be added to the settings.php file used for the site.
```
php
$conf
[
'page_cache_without_database'
]
=
TRUE
;
$conf
[
'page_cache_invoke_hooks'
]
=
FALSE
;
```
In case of multi-site installations, you can use one of the following lines in
the settings.php file for each site to avoid that values cached for a site are
returned for all the sites.
```
php
// release 7.x-1.0
$conf
[
'cache_prefix'
]
=
drupal_random_bytes
(
8
);
// release 7.x-2.0
$conf
[
'apc_cache_prefix'
]
=
drupal_random_bytes
(
8
);
```
It is also possible to provide a different prefix for each cache bin, for
example using the following lines.
```
php
$conf
[
'apc_cache_prefix'
]
=
array
(
'cache'
=>
drupal_random_bytes
(
8
),
'cache_bootstrap'
=>
drupal_random_bytes
(
8
),
'default'
=>
drupal_random_bytes
(
8
),
);
```
`$conf['apc_cache_prefix']['default']`
is used for all the cache bins for which
no prefix is provided.
The Alternative PHP Cache module uses the database information to avoid
conflicts in case of multi-site installations, but setting
`$conf['apc_cache_prefix']`
can help to further avoid conflicts.
Finally, to enable debugging, add the following line.
```
php
$conf
[
'apc_show_debug'
]
=
TRUE
;
```
When debugging is enabled, each page will show a list of the operations done on
the cache, for example which cache items were removed, which ones were added or
updated.
Only the accounts with the
*access apc statistics*
permission will be
able to see that information.
## Maintainers
-
Alberto Paderno -
[
avpaderno
](
https://www.drupal.org/u/avpaderno
)
(
Drupal
7)
-
Raymond Muilwijk -
[
R.Muilwijk
](
https://www.drupal.org/u/rmuilwijk
)
(
Drupal
7)
-
Steve Rude -
[
slantview
](
https://www.drupal.org/u/slantview
)
(
Drupal
5 and 6)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment