Skip to content

Commit 1e42c9d

Browse files
Jordan's review
Co-authored-by: Jordan Smith <[email protected]>
1 parent 1940776 commit 1e42c9d

File tree

1 file changed

+34
-33
lines changed

1 file changed

+34
-33
lines changed

docs/cache.txt

+34-33
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ Cache and Locks
66

77
.. facet::
88
:name: genre
9-
:values: tutorial
9+
:values: reference
1010

1111
.. meta::
1212
:keywords: php framework, cache, lock, code example
1313

1414
Configuration
1515
-------------
1616

17-
In order to use MongoDB as backend for `Laravel Cache and Locks <https://laravel.com/docs/{+laravel-docs-version+}/cache>`__,
18-
add a store configuration using the ``mongodb`` driver in ``config/cache.php``:
17+
To use MongoDB as a backend for `Laravel Cache and Locks <https://laravel.com/docs/{+laravel-docs-version+}/cache>`__,
18+
add a store configuration by using the ``mongodb`` driver in ``config/cache.php``:
1919

2020
.. code-block:: php
2121

@@ -45,13 +45,13 @@ and their default values:
4545
- **Required**. Specifies the lock driver to use. Must be ``mongodb``.
4646

4747
* - ``connection``
48-
- **Required**. The database connection to use to store cache items. It must be a ``mongodb`` connection.
48+
- **Required**. The database connection used to store cache items. It must be a ``mongodb`` connection.
4949

5050
* - ``collection``
5151
- Default ``cache``. Name of the MongoDB collection to store cache items.
5252

5353
* - ``lock_connection``
54-
- Default to the cache ``connection``. The database connection to use to store locks. It must be a ``mongodb`` connection.
54+
- Default to the cache ``connection``. The database connection used to store locks. It must be a ``mongodb`` connection.
5555

5656
* - ``lock_collection``
5757
- Default ``cache_locks``. Name of the MongoDB collection to store locks.
@@ -60,20 +60,20 @@ and their default values:
6060
- Default ``[2, 100]``. Probability [chance, total] of pruning expired cache items. Set to [0, 0] to disable
6161

6262
* - ``lock_timeout``
63-
- Default ``86400``. Time-to-live of the locks in seconds
63+
- Default ``86400``. Time-to-live of the locks, in seconds.
6464

6565

66-
Setup auto-expiration indexes
66+
Setup Auto-Expiration Indexes
6767
-----------------------------
6868

6969
The :manual:`TTL indexes </core/index-ttl/>` integrated into MongoDB automatically
70-
delete documents when they have expired. Their use is optional with the ``mongodb``
71-
driver, but recommended as they provide better performance by delegating the
70+
delete documents when they expire. Their use is optional with the ``mongodb``
71+
driver, but recommended, because they provide better performance by delegating the
7272
deletion of expired documents to MongoDB instead of requiring the application to
7373
perform this task randomly.
7474

75-
The best way is to create the indexes with a migration calling the methods
76-
``createTTLIndex()`` provided by both the cache and the lock stores:
75+
Create the indexes with a migration that calls the
76+
``createTTLIndex()`` methods provided by both the cache, and the lock stores:
7777

7878
.. literalinclude:: /includes/cache/migration.php
7979
:language: php
@@ -84,9 +84,9 @@ Then run the migration:
8484

8585
.. code-block:: none
8686

87-
$ php artisan migrate
87+
php artisan migrate
8888

89-
Alternatively, the index can be created using :mdb-shell:`MongoDB Shell <>` (``mongosh``):
89+
Alternatively, you can create the index by using :mdb-shell:`MongoDB Shell <>` (``mongosh``):
9090

9191
.. code-block:: ts
9292

@@ -110,36 +110,37 @@ If you use Locks, disable ``lock_lottery`` by setting the probability to ``0``:
110110
],
111111
],
112112

113-
Using MongoDB cache
113+
Using MongoDB Cache
114114
-------------------
115115

116116
The Laravel cache can be used to store any serializable data using the facade
117-
``Illuminate\Support\Facades\Cache``:
117+
``Illuminate\Support\Facades\Cache``.
118118

119-
In this example:
120-
- Gets the cache repository with the store ``mongodb``,
121-
- Tries to read and return the cache item named ``foo``,
122-
- If missing, calls the closure to compute the value, store this value forever and return it.
119+
This example performs the following actions:
123120

124-
..code-block:: php
121+
- Gets the cache repository with the ``mongodb`` store
122+
- Tries to read and return the cache item named ``foo``
123+
- If missing, calls the closure to compute the value, stores the value forever, and returns it
124+
125+
.. code-block:: php
125126

126127
use Illuminate\Support\Facades\Cache;
127128

128129
$value = Cache::store('mongodb')->get('foo', function () {
129130
return [1, 2, 3];
130131
});
131132

132-
The default, cached objects do not expire. It is possible to define an expiry time.
133+
By default, cached objects do not expire. However, it is possible to define an expiry time, as shown in the following example:
133134

134-
..code-block:: php
135+
.. code-block:: php
135136

136137
Cache::store('mongodb')->set('foo', 'abc', '1 day');
137138

138-
Incrementing and decrementing a value is also supported, the value must
139-
be initialized before. The following example initialize the counter to ``3``,
140-
adds 5 and removes 2.
139+
Incrementing and decrementing a value is also supported if the value is
140+
initialized before. The following example initializes the counter to ``3``,
141+
adds 5, and removes 2.
141142

142-
..code-block:: php
143+
.. code-block:: php
143144

144145
Cache::store('mongodb')->set('counter', 3);
145146
Cache::store('mongodb')->increment('counter', 5);
@@ -149,7 +150,7 @@ adds 5 and removes 2.
149150

150151
{+odm-short+} supports incrementing and decrementing with integer and float values.
151152

152-
Configuring MongoDB as default cache
153+
Configuring MongoDB as Default Cache
153154
------------------------------------
154155

155156
To use the ``mongodb`` store by default, change the default store in
@@ -169,8 +170,8 @@ To use the ``mongodb`` store by default, change the default store in
169170
],
170171
];
171172

172-
The variable ``CACHE_STORE`` could be set in your environment or in
173-
the ``.env`` file. Update or remove it:
173+
The variable ``CACHE_STORE`` can be set in your environment or in
174+
the ``.env`` file. Update or remove it as follows:
174175

175176
.. code-block:: none
176177

@@ -185,8 +186,8 @@ automatic injection:
185186

186187
Cache::get('foo', 5);
187188

188-
This example shows how to use automatic injection of the cache
189-
manager, using the default store. It is a controller that
189+
The following example shows how to use automatic injection of the cache
190+
manager by using the default store. The example creates a controller that
190191
increments a counter each time it is invoked.
191192

192193

@@ -216,9 +217,9 @@ Using MongoDB Lock
216217
------------------
217218

218219
Atomic locks allow for the manipulation of distributed locks without worrying
219-
about race conditions.
220+
about race conditions. The following example implements an atomic lock:
220221

221-
..code-block:: php
222+
.. code-block:: php
222223
:emphasize-lines: 3
223224

224225
use Illuminate\Support\Facades\Cache;

0 commit comments

Comments
 (0)