-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclassdpp_1_1cache.html
563 lines (529 loc) · 38.2 KB
/
classdpp_1_1cache.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="utf-8">
<meta property="og:title" content="dpp::cache< T > Class Template Reference - D++ - The lightweight C++ Discord API Library">
<meta property="og:description" content="A lightweight C++ Discord API library supporting the entire Discord API, including Slash Commands, Voice/Audio, Sharding, Clustering and more!">
<meta name="description" content="dpp::cache< T > Class Template Reference - D++ - A lightweight C++ Discord API library supporting the entire Discord API, including Slash Commands, Voice/Audio, Sharding, Clustering and more!">
<meta property="og:image" content="https://dpp.dev/DPP-Logo.png">
<meta property="og:url" content="https://dpp.dev/">
<meta property="og:type" content="website">
<meta property="twitter:title" content="dpp::cache< T > Class Template Reference - D++ - The lightweight C++ Discord API Library">
<title>dpp::cache< T > Class Template Reference - D++ - The lightweight C++ Discord API Library</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="doxygen-awesome.css" rel="stylesheet" type="text/css"/>
<link href="style.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<script>
setTimeout(function() {
$("#main-menu").html($("#main-menu").html() + "<li><select name='vsv' onchange='window.location.href=this.options[this.selectedIndex].value'><option value='/'>master</option><option value='/10.0.35/'>10.0.35</option><option value='/10.0.34/'>10.0.34</option><option value='/10.0.33/'>10.0.33</option><option value='/10.0.32/'>10.0.32</option><option value='/10.0.31/'>10.0.31</option><option value='/10.0.30/'>10.0.30</option><option value='/10.0.29/'>10.0.29</option><option value='/10.0.28/'>10.0.28</option><option value='/10.0.27/'>10.0.27</option><option value='/10.0.26/'>10.0.26</option><option value='/10.0.25/'>10.0.25</option><option value='/10.0.24/'>10.0.24</option><option value='/10.0.23/'>10.0.23</option><option value='/10.0.22/'>10.0.22</option><option value='/10.0.21/'>10.0.21</option><option value='/10.0.20/'>10.0.20</option><option value='/10.0.19/'>10.0.19</option><option value='/10.0.18/'>10.0.18</option><option value='/10.0.17/'>10.0.17</option><option value='/10.0.16/'>10.0.16</option><option value='/10.0.15/'>10.0.15</option><option value='/10.0.14/'>10.0.14</option><option selected value='/10.0.13/'>10.0.13</option><option value='/10.0.12/'>10.0.12</option><option value='/10.0.11/'>10.0.11</option><option value='/10.0.10/'>10.0.10</option><option value='/10.0.9/'>10.0.9</option><option value='/10.0.8/'>10.0.8</option><option value='/10.0.7/'>10.0.7</option><option value='/10.0.6/'>10.0.6</option><option value='/10.0.5/'>10.0.5</option><option value='/10.0.4/'>10.0.4</option><option value='/10.0.3/'>10.0.3</option><option value='/10.0.2/'>10.0.2</option><option value='/10.0.1/'>10.0.1</option><option value='/10.0.0/'>10.0.0</option><option value='/9.0.19/'>9.0.19</option><option value='/9.0.18/'>9.0.18</option><option value='/9.0.17/'>9.0.17</option><option value='/9.0.16/'>9.0.16</option><option value='/9.0.15/'>9.0.15</option><option value='/9.0.14/'>9.0.14</option><option value='/9.0.13/'>9.0.13</option><option value='/9.0.12/'>9.0.12</option><option value='/9.0.11/'>9.0.11</option><option value='/9.0.10/'>9.0.10</option><option value='/9.0.9/'>9.0.9</option><option value='/9.0.8/'>9.0.8</option><option value='/9.0.7/'>9.0.7</option><option value='/9.0.6/'>9.0.6</option><option value='/9.0.5/'>9.0.5</option><option value='/9.0.4/'>9.0.4</option><option value='/9.0.3/'>9.0.3</option><option value='/9.0.2/'>9.0.2</option><option value='/9.0.1/'>9.0.1</option><option value='/9.0.0/'>9.0.0</option><option value='/1.0.2/'>1.0.2</option><option value='/1.0.1/'>1.0.1</option><option value='/1.0.0/'>1.0.0</option></select></li>");
}, 500);
</script>
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td id="projectlogo"><img alt="Logo" src="DPP-Logo.png"/></td>
<td style="padding-left: 0.5em;">
<div id="projectname">D++ (DPP)
</div>
<div id="projectbrief">C++ Discord API Bot Library</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<label for="MSearchField" style="display: none">Search</label>
<!-- Generated by Doxygen 1.9.3 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search",'Search','.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
$(function() {
initMenu('',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
$(document).ready(function(){initNavTree('classdpp_1_1cache.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<div class="header">
<div class="summary">
<a href="#pub-methods">Public Member Functions</a> |
<a href="classdpp_1_1cache-members.html">List of all members</a> </div>
<div class="headertitle"><div class="title">dpp::cache< T > Class Template Reference</div></div>
</div><!--header-->
<div class="contents">
<p>A cache object maintains a cache of <a class="el" href="classdpp_1_1managed.html" title="The managed class is the base class for various types that can be stored in a cache that are identifi...">dpp::managed</a> objects.
<a href="classdpp_1_1cache.html#details">More...</a></p>
<p><code>#include <cache.h></code></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="pub-methods" name="pub-methods"></a>
Public Member Functions</h2></td></tr>
<tr class="memitem:ae7b01fd8baebf24d31f6e0e2f15df8e2"><td class="memItemLeft" align="right" valign="top"> </td><td class="memItemRight" valign="bottom"><a class="el" href="classdpp_1_1cache.html#ae7b01fd8baebf24d31f6e0e2f15df8e2">cache</a> ()</td></tr>
<tr class="memdesc:ae7b01fd8baebf24d31f6e0e2f15df8e2"><td class="mdescLeft"> </td><td class="mdescRight">Construct a new cache object. <a href="classdpp_1_1cache.html#ae7b01fd8baebf24d31f6e0e2f15df8e2">More...</a><br /></td></tr>
<tr class="separator:ae7b01fd8baebf24d31f6e0e2f15df8e2"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:a9e99a62833153d92a3dd160ae91b031b"><td class="memItemLeft" align="right" valign="top"> </td><td class="memItemRight" valign="bottom"><a class="el" href="classdpp_1_1cache.html#a9e99a62833153d92a3dd160ae91b031b">~cache</a> ()</td></tr>
<tr class="memdesc:a9e99a62833153d92a3dd160ae91b031b"><td class="mdescLeft"> </td><td class="mdescRight">Destroy the cache object. <a href="classdpp_1_1cache.html#a9e99a62833153d92a3dd160ae91b031b">More...</a><br /></td></tr>
<tr class="separator:a9e99a62833153d92a3dd160ae91b031b"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:ab2aa9a2fbf0cb47d49d4bba05c2e2039"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="classdpp_1_1cache.html#ab2aa9a2fbf0cb47d49d4bba05c2e2039">store</a> (T *object)</td></tr>
<tr class="memdesc:ab2aa9a2fbf0cb47d49d4bba05c2e2039"><td class="mdescLeft"> </td><td class="mdescRight">Store an object in the cache. Passing a nullptr will have no effect. <a href="classdpp_1_1cache.html#ab2aa9a2fbf0cb47d49d4bba05c2e2039">More...</a><br /></td></tr>
<tr class="separator:ab2aa9a2fbf0cb47d49d4bba05c2e2039"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:a4994e44f3ec37d08acc8c064c95746ad"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="classdpp_1_1cache.html#a4994e44f3ec37d08acc8c064c95746ad">remove</a> (T *object)</td></tr>
<tr class="memdesc:a4994e44f3ec37d08acc8c064c95746ad"><td class="mdescLeft"> </td><td class="mdescRight">Remove an object from the cache. <a href="classdpp_1_1cache.html#a4994e44f3ec37d08acc8c064c95746ad">More...</a><br /></td></tr>
<tr class="separator:a4994e44f3ec37d08acc8c064c95746ad"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:abf1e2911e8e1559fa15a36c5f90454d3"><td class="memItemLeft" align="right" valign="top">T * </td><td class="memItemRight" valign="bottom"><a class="el" href="classdpp_1_1cache.html#abf1e2911e8e1559fa15a36c5f90454d3">find</a> (<a class="el" href="namespacedpp.html#a0dec2a52b080906aebfd3e1b3db02475">snowflake</a> id)</td></tr>
<tr class="memdesc:abf1e2911e8e1559fa15a36c5f90454d3"><td class="mdescLeft"> </td><td class="mdescRight">Find an object in the cache by id. <a href="classdpp_1_1cache.html#abf1e2911e8e1559fa15a36c5f90454d3">More...</a><br /></td></tr>
<tr class="separator:abf1e2911e8e1559fa15a36c5f90454d3"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:a63fb9389314371ca017647db2aad53f1"><td class="memItemLeft" align="right" valign="top">uint64_t </td><td class="memItemRight" valign="bottom"><a class="el" href="classdpp_1_1cache.html#a63fb9389314371ca017647db2aad53f1">count</a> ()</td></tr>
<tr class="memdesc:a63fb9389314371ca017647db2aad53f1"><td class="mdescLeft"> </td><td class="mdescRight">Return a count of the number of items in the cache. <a href="classdpp_1_1cache.html#a63fb9389314371ca017647db2aad53f1">More...</a><br /></td></tr>
<tr class="separator:a63fb9389314371ca017647db2aad53f1"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:a5ff19cda1ffdfaa11f0e4027ba8d1b76"><td class="memItemLeft" align="right" valign="top">std::shared_mutex & </td><td class="memItemRight" valign="bottom"><a class="el" href="classdpp_1_1cache.html#a5ff19cda1ffdfaa11f0e4027ba8d1b76">get_mutex</a> ()</td></tr>
<tr class="memdesc:a5ff19cda1ffdfaa11f0e4027ba8d1b76"><td class="mdescLeft"> </td><td class="mdescRight">Return the cache's locking mutex. <a href="classdpp_1_1cache.html#a5ff19cda1ffdfaa11f0e4027ba8d1b76">More...</a><br /></td></tr>
<tr class="separator:a5ff19cda1ffdfaa11f0e4027ba8d1b76"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:ab7647df5af8f7bf01826bf650b157aa4"><td class="memItemLeft" align="right" valign="top">auto & </td><td class="memItemRight" valign="bottom"><a class="el" href="classdpp_1_1cache.html#ab7647df5af8f7bf01826bf650b157aa4">get_container</a> ()</td></tr>
<tr class="memdesc:ab7647df5af8f7bf01826bf650b157aa4"><td class="mdescLeft"> </td><td class="mdescRight">Get the container unordered map. <a href="classdpp_1_1cache.html#ab7647df5af8f7bf01826bf650b157aa4">More...</a><br /></td></tr>
<tr class="separator:ab7647df5af8f7bf01826bf650b157aa4"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:af1c53b4d84ae2d1c1fbf8d540d884034"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="classdpp_1_1cache.html#af1c53b4d84ae2d1c1fbf8d540d884034">rehash</a> ()</td></tr>
<tr class="memdesc:af1c53b4d84ae2d1c1fbf8d540d884034"><td class="mdescLeft"> </td><td class="mdescRight">"Rehash" a cache by reallocating the map and copying all elements into the new one. <a href="classdpp_1_1cache.html#af1c53b4d84ae2d1c1fbf8d540d884034">More...</a><br /></td></tr>
<tr class="separator:af1c53b4d84ae2d1c1fbf8d540d884034"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:a9b2dc568fe8e6e92006a3bf3891b74c3"><td class="memItemLeft" align="right" valign="top">size_t </td><td class="memItemRight" valign="bottom"><a class="el" href="classdpp_1_1cache.html#a9b2dc568fe8e6e92006a3bf3891b74c3">bytes</a> ()</td></tr>
<tr class="memdesc:a9b2dc568fe8e6e92006a3bf3891b74c3"><td class="mdescLeft"> </td><td class="mdescRight">Get "real" size in RAM of the cached objects. <a href="classdpp_1_1cache.html#a9b2dc568fe8e6e92006a3bf3891b74c3">More...</a><br /></td></tr>
<tr class="separator:a9b2dc568fe8e6e92006a3bf3891b74c3"><td class="memSeparator" colspan="2"> </td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><div class="compoundTemplParams">template<class T><br />
class dpp::cache< T ></div><p >A cache object maintains a cache of <a class="el" href="classdpp_1_1managed.html" title="The managed class is the base class for various types that can be stored in a cache that are identifi...">dpp::managed</a> objects. </p>
<p >This is for example users, channels or guilds. You may instantiate your own caches, to contain any type derived from <a class="el" href="classdpp_1_1managed.html" title="The managed class is the base class for various types that can be stored in a cache that are identifi...">dpp::managed</a> including your own types.</p>
<dl class="section note"><dt>Note</dt><dd>This class is critical to the operation of the library and therefore designed with thread safety in mind. </dd></dl>
<dl class="tparams"><dt>Template Parameters</dt><dd>
<table class="tparams">
<tr><td class="paramname">T</td><td>class type to store, which should be derived from <a class="el" href="classdpp_1_1managed.html" title="The managed class is the base class for various types that can be stored in a cache that are identifi...">dpp::managed</a>. </td></tr>
</table>
</dd>
</dl>
</div><h2 class="groupheader">Constructor & Destructor Documentation</h2>
<a id="ae7b01fd8baebf24d31f6e0e2f15df8e2" name="ae7b01fd8baebf24d31f6e0e2f15df8e2"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ae7b01fd8baebf24d31f6e0e2f15df8e2">◆ </a></span>cache()</h2>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template<class T > </div>
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname"><a class="el" href="classdpp_1_1cache.html">dpp::cache</a>< T >::<a class="el" href="classdpp_1_1cache.html">cache</a> </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<p>Construct a new cache object. </p>
<p >Caches must contain classes derived from <a class="el" href="classdpp_1_1managed.html" title="The managed class is the base class for various types that can be stored in a cache that are identifi...">dpp::managed</a>. </p>
</div>
</div>
<a id="a9e99a62833153d92a3dd160ae91b031b" name="a9e99a62833153d92a3dd160ae91b031b"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a9e99a62833153d92a3dd160ae91b031b">◆ </a></span>~cache()</h2>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template<class T > </div>
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname"><a class="el" href="classdpp_1_1cache.html">dpp::cache</a>< T >::~<a class="el" href="classdpp_1_1cache.html">cache</a> </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<p>Destroy the cache object. </p>
<dl class="section note"><dt>Note</dt><dd>This does not delete objects stored in the cache. </dd></dl>
</div>
</div>
<h2 class="groupheader">Member Function Documentation</h2>
<a id="a9b2dc568fe8e6e92006a3bf3891b74c3" name="a9b2dc568fe8e6e92006a3bf3891b74c3"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a9b2dc568fe8e6e92006a3bf3891b74c3">◆ </a></span>bytes()</h2>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template<class T > </div>
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname">size_t <a class="el" href="classdpp_1_1cache.html">dpp::cache</a>< T >::bytes </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<p>Get "real" size in RAM of the cached objects. </p>
<p >This does not include metadata used to maintain the unordered map itself.</p>
<dl class="section return"><dt>Returns</dt><dd>size_t size of cache in bytes </dd></dl>
</div>
</div>
<a id="a63fb9389314371ca017647db2aad53f1" name="a63fb9389314371ca017647db2aad53f1"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a63fb9389314371ca017647db2aad53f1">◆ </a></span>count()</h2>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template<class T > </div>
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname">uint64_t <a class="el" href="classdpp_1_1cache.html">dpp::cache</a>< T >::count </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<p>Return a count of the number of items in the cache. </p>
<p >This is used by the library e.g. to count guilds, users, and roles stored within caches. get </p><dl class="section return"><dt>Returns</dt><dd>uint64_t count of items in the cache </dd></dl>
</div>
</div>
<a id="abf1e2911e8e1559fa15a36c5f90454d3" name="abf1e2911e8e1559fa15a36c5f90454d3"></a>
<h2 class="memtitle"><span class="permalink"><a href="#abf1e2911e8e1559fa15a36c5f90454d3">◆ </a></span>find()</h2>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template<class T > </div>
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname">T * <a class="el" href="classdpp_1_1cache.html">dpp::cache</a>< T >::find </td>
<td>(</td>
<td class="paramtype"><a class="el" href="namespacedpp.html#a0dec2a52b080906aebfd3e1b3db02475">snowflake</a> </td>
<td class="paramname"><em>id</em></td><td>)</td>
<td></td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<p>Find an object in the cache by id. </p>
<p >The cache is searched for the object. All <a class="el" href="classdpp_1_1managed.html" title="The managed class is the base class for various types that can be stored in a cache that are identifi...">dpp::managed</a> objects have a snowflake id (this is the only field <a class="el" href="classdpp_1_1managed.html" title="The managed class is the base class for various types that can be stored in a cache that are identifi...">dpp::managed</a> actually has).</p>
<dl class="section warning"><dt>Warning</dt><dd>Do not hang onto objects returned by <a class="el" href="classdpp_1_1cache.html#abf1e2911e8e1559fa15a36c5f90454d3" title="Find an object in the cache by id.">cache::find()</a> indefinitely. They may be deleted at a later date if <a class="el" href="classdpp_1_1cache.html#a4994e44f3ec37d08acc8c064c95746ad" title="Remove an object from the cache.">cache::remove()</a> is called. If persistence is required, take a copy of the object after checking its pointer is non-null.</dd></dl>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">id</td><td>Object snowflake id to find </td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>Found object or nullptr if the object with this id does not exist. </dd></dl>
</div>
</div>
<a id="ab7647df5af8f7bf01826bf650b157aa4" name="ab7647df5af8f7bf01826bf650b157aa4"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ab7647df5af8f7bf01826bf650b157aa4">◆ </a></span>get_container()</h2>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template<class T > </div>
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname">auto & <a class="el" href="classdpp_1_1cache.html">dpp::cache</a>< T >::get_container </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<p>Get the container unordered map. </p>
<dl class="section warning"><dt>Warning</dt><dd>Be sure to use <a class="el" href="classdpp_1_1cache.html#a5ff19cda1ffdfaa11f0e4027ba8d1b76" title="Return the cache's locking mutex.">cache::get_mutex()</a> correctly if you manipulate or iterate the map returned by this method! If you do not, this is not thread safe and will cause crashes!</dd></dl>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="classdpp_1_1cache.html#a5ff19cda1ffdfaa11f0e4027ba8d1b76" title="Return the cache's locking mutex.">cache::get_mutex</a></dd></dl>
<dl class="section return"><dt>Returns</dt><dd>A reference to the cache's container map </dd></dl>
</div>
</div>
<a id="a5ff19cda1ffdfaa11f0e4027ba8d1b76" name="a5ff19cda1ffdfaa11f0e4027ba8d1b76"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a5ff19cda1ffdfaa11f0e4027ba8d1b76">◆ </a></span>get_mutex()</h2>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template<class T > </div>
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname">std::shared_mutex & <a class="el" href="classdpp_1_1cache.html">dpp::cache</a>< T >::get_mutex </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<p>Return the cache's locking mutex. </p>
<p >Use this whenever you manipulate or iterate raw elements in the cache!</p>
<dl class="section note"><dt>Note</dt><dd>If you are only reading from the cache's container, wrap this mutex in <code>std::shared_lock</code>, else wrap it in a <code>std::unique_lock</code>. Shared locks will allow for multiple readers whilst blocking writers, and unique locks will allow only one writer whilst blocking readers and writers.</dd></dl>
<p><b>Example:</b></p>
<div class="fragment"><div class="line"><a class="code hl_class" href="classdpp_1_1cache.html">dpp::cache<guild></a>* c = <a class="code hl_function" href="namespacedpp.html#a5ae7c530cff1cae7200e136bf8c1bf83">dpp::get_guild_cache</a>();</div>
<div class="line">std::unordered_map<snowflake, guild*>& gc = c-><a class="code hl_function" href="classdpp_1_1cache.html#ab7647df5af8f7bf01826bf650b157aa4">get_container</a>();</div>
<div class="line">std::shared_lock l(c-><a class="code hl_function" href="classdpp_1_1cache.html#a5ff19cda1ffdfaa11f0e4027ba8d1b76">get_mutex</a>()); <span class="comment">// MUST LOCK HERE</span></div>
<div class="line"><span class="keywordflow">for</span> (<span class="keyword">auto</span> g = gc.begin(); g != gc.end(); ++g) {</div>
<div class="line"> <a class="code hl_class" href="classdpp_1_1guild.html">dpp::guild</a>* gp = (<a class="code hl_class" href="classdpp_1_1guild.html">dpp::guild</a>*)g->second;</div>
<div class="line"> <span class="comment">// Do something here with the guild* in 'gp'</span></div>
<div class="line">}</div>
<div class="ttc" id="aclassdpp_1_1cache_html"><div class="ttname"><a href="classdpp_1_1cache.html">dpp::cache</a></div><div class="ttdoc">A cache object maintains a cache of dpp::managed objects.</div><div class="ttdef"><b>Definition:</b> cache.h:49</div></div>
<div class="ttc" id="aclassdpp_1_1cache_html_a5ff19cda1ffdfaa11f0e4027ba8d1b76"><div class="ttname"><a href="classdpp_1_1cache.html#a5ff19cda1ffdfaa11f0e4027ba8d1b76">dpp::cache::get_mutex</a></div><div class="ttdeci">std::shared_mutex & get_mutex()</div><div class="ttdoc">Return the cache's locking mutex.</div><div class="ttdef"><b>Definition:</b> cache.h:200</div></div>
<div class="ttc" id="aclassdpp_1_1cache_html_ab7647df5af8f7bf01826bf650b157aa4"><div class="ttname"><a href="classdpp_1_1cache.html#ab7647df5af8f7bf01826bf650b157aa4">dpp::cache::get_container</a></div><div class="ttdeci">auto & get_container()</div><div class="ttdoc">Get the container unordered map.</div><div class="ttdef"><b>Definition:</b> cache.h:215</div></div>
<div class="ttc" id="aclassdpp_1_1guild_html"><div class="ttname"><a href="classdpp_1_1guild.html">dpp::guild</a></div><div class="ttdoc">Represents a guild on Discord (AKA a server)</div><div class="ttdef"><b>Definition:</b> guild.h:384</div></div>
<div class="ttc" id="anamespacedpp_html_a5ae7c530cff1cae7200e136bf8c1bf83"><div class="ttname"><a href="namespacedpp.html#a5ae7c530cff1cae7200e136bf8c1bf83">dpp::get_guild_cache</a></div><div class="ttdeci">DPP_EXPORT cache< class guild > * get_guild_cache()</div></div>
</div><!-- fragment --><dl class="section return"><dt>Returns</dt><dd>The mutex used to protect the container </dd></dl>
</div>
</div>
<a id="af1c53b4d84ae2d1c1fbf8d540d884034" name="af1c53b4d84ae2d1c1fbf8d540d884034"></a>
<h2 class="memtitle"><span class="permalink"><a href="#af1c53b4d84ae2d1c1fbf8d540d884034">◆ </a></span>rehash()</h2>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template<class T > </div>
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname">void <a class="el" href="classdpp_1_1cache.html">dpp::cache</a>< T >::rehash </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<p>"Rehash" a cache by reallocating the map and copying all elements into the new one. </p>
<p >Over a long running timeframe, unordered maps can grow in size due to bucket allocation, this function frees that unused memory to keep the maps in control over time. If this is an issue which is apparent with your use of <a class="el" href="classdpp_1_1cache.html" title="A cache object maintains a cache of dpp::managed objects.">dpp::cache</a> objects, you should periodically call this method.</p>
<dl class="section warning"><dt>Warning</dt><dd>May be time consuming! This function is O(n) in relation to the number of cached entries. </dd></dl>
</div>
</div>
<a id="a4994e44f3ec37d08acc8c064c95746ad" name="a4994e44f3ec37d08acc8c064c95746ad"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a4994e44f3ec37d08acc8c064c95746ad">◆ </a></span>remove()</h2>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template<class T > </div>
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname">void <a class="el" href="classdpp_1_1cache.html">dpp::cache</a>< T >::remove </td>
<td>(</td>
<td class="paramtype">T * </td>
<td class="paramname"><em>object</em></td><td>)</td>
<td></td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<p>Remove an object from the cache. </p>
<dl class="section note"><dt>Note</dt><dd>The cache class takes ownership of the pointer, and calling this method will cause deletion of the object within the next 60 seconds by means of a garbage collection queue. This queue aids in efficiency by freeing memory in bulk, and assists in thread safety by ensuring that all deletions can be locked and freed at the same time.</dd></dl>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">object</td><td>object to remove. Passing a nullptr will have no effect. </td></tr>
</table>
</dd>
</dl>
</div>
</div>
<a id="ab2aa9a2fbf0cb47d49d4bba05c2e2039" name="ab2aa9a2fbf0cb47d49d4bba05c2e2039"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ab2aa9a2fbf0cb47d49d4bba05c2e2039">◆ </a></span>store()</h2>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template<class T > </div>
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname">void <a class="el" href="classdpp_1_1cache.html">dpp::cache</a>< T >::store </td>
<td>(</td>
<td class="paramtype">T * </td>
<td class="paramname"><em>object</em></td><td>)</td>
<td></td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<p>Store an object in the cache. Passing a nullptr will have no effect. </p>
<p >The object must be derived from <a class="el" href="classdpp_1_1managed.html" title="The managed class is the base class for various types that can be stored in a cache that are identifi...">dpp::managed</a> and should be allocated on the heap. Generally this is done via <code>new</code>. Once stored in the cache the lifetime of the stored object is managed by the cache class unless the cache is deleted (at which point responsibility for deleting the object returns to its allocator). Objects stored are removed when the <a class="el" href="classdpp_1_1cache.html#a4994e44f3ec37d08acc8c064c95746ad" title="Remove an object from the cache.">cache::remove()</a> method is called by placing them into a garbage collection queue for deletion within the next 60 seconds, which are then deleted in bulk for efficiency and to aid thread safety.</p>
<dl class="section note"><dt>Note</dt><dd>Adding an object to the cache with an ID which already exists replaces that entry. The previously entered cache item is inserted into the garbage collection queue for deletion similarly to if <a class="el" href="classdpp_1_1cache.html#a4994e44f3ec37d08acc8c064c95746ad" title="Remove an object from the cache.">cache::remove()</a> was called first.</dd></dl>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">object</td><td>object to store. Storing a pointer to the cache relinquishes ownership to the cache object. </td></tr>
</table>
</dd>
</dl>
</div>
</div>
</div><!-- contents --><script src="https://giscus.app/client.js" data-repo="brainboxdotcc/dpp-comments" data-repo-id="R_kgDOHOY4xg" data-category="General" data-category-id="DIC_kwDOHOY4xs4CRYtj" data-mapping="pathname" data-strict="1" data-reactions-enabled="1" data-emit-metadata="1" data-input-position="top" data-theme="preferred_color_scheme" data-lang="en" data-loading="lazy" crossorigin="anonymous" async></script>
</div><!-- doc-content -->
<div id="nav-path" class="navpath">
<ul>
<li class="navelem"><a class="el" href="namespacedpp.html">dpp</a></li><li class="navelem"><a class="el" href="classdpp_1_1cache.html">cache</a></li>
</ul>
</div>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-QTH6YHBNG5"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.6.0/styles/base16/dracula.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.6.0/highlight.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlightjs-line-numbers.js/2.8.0/highlightjs-line-numbers.min.js"></script>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@100&display=swap" rel="stylesheet">
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-QTH6YHBNG5');
$(function() {
$(".fragment").each(function(i,node) {
var $node = $(node);
$node.children(":not(.line)").remove();
$node.html("<pre><code class='stan'>" + $node.text().trim().replaceAll("<", "<").replaceAll(">", ">") + "</code></pre>");
hljs.configure({
languages: ['cpp','diff','cmake','bash','sh','text'],
ignoreUnescapedHTML: true
});
hljs.highlightAll(node);
hljs.initLineNumbersOnLoad(node);
});
$(".fragment").parent().parent().parent().parent().removeClass('doxtable');
});
</script>
<style>
.hljs-ln-code, code, code a, pre.fragment, div.fragment, div.fragment .line, div.fragment span, div.fragment .line a, div.fragment .line span {
font-family: 'JetBrains Mono', monospace !important;
font-size: 0.8rem !important;
}
.fragment {
padding: 0 !important;
margin-top: 0 !important;
margin-bottom: 0 !important;
background: none !important;
border: 0 !important;
}
.hljs-ln-n::before {
content: attr(data-line-number);
padding-right: 1rem !important;
}
table.markdownTable code td, table.markdownTable code th, table.fieldtable code td, table.fieldtable code th, table.doxtable code td, table.doxtable code th {
border: 0 !important;
padding: 0 !important;
}
</style>
<div style="z-index: -9999; position: absolute; right: 0; top: 0; font-size: 0.0001rem;color:transparent;background:none">
<!-- For crawlability of past versions -->
<a href='/10.0.35/'>D++ Library version 10.0.35</a><a href='/10.0.34/'>D++ Library version 10.0.34</a><a href='/10.0.33/'>D++ Library version 10.0.33</a><a href='/10.0.32/'>D++ Library version 10.0.32</a><a href='/10.0.31/'>D++ Library version 10.0.31</a><a href='/10.0.30/'>D++ Library version 10.0.30</a><a href='/10.0.29/'>D++ Library version 10.0.29</a><a href='/10.0.28/'>D++ Library version 10.0.28</a><a href='/10.0.27/'>D++ Library version 10.0.27</a><a href='/10.0.26/'>D++ Library version 10.0.26</a><a href='/10.0.25/'>D++ Library version 10.0.25</a><a href='/10.0.24/'>D++ Library version 10.0.24</a><a href='/10.0.23/'>D++ Library version 10.0.23</a><a href='/10.0.22/'>D++ Library version 10.0.22</a><a href='/10.0.21/'>D++ Library version 10.0.21</a><a href='/10.0.20/'>D++ Library version 10.0.20</a><a href='/10.0.19/'>D++ Library version 10.0.19</a><a href='/10.0.18/'>D++ Library version 10.0.18</a><a href='/10.0.17/'>D++ Library version 10.0.17</a><a href='/10.0.16/'>D++ Library version 10.0.16</a><a href='/10.0.15/'>D++ Library version 10.0.15</a><a href='/10.0.14/'>D++ Library version 10.0.14</a><a href='/10.0.13/'>D++ Library version 10.0.13</a><a href='/10.0.12/'>D++ Library version 10.0.12</a><a href='/10.0.11/'>D++ Library version 10.0.11</a><a href='/10.0.10/'>D++ Library version 10.0.10</a><a href='/10.0.9/'>D++ Library version 10.0.9</a><a href='/10.0.8/'>D++ Library version 10.0.8</a><a href='/10.0.7/'>D++ Library version 10.0.7</a><a href='/10.0.6/'>D++ Library version 10.0.6</a><a href='/10.0.5/'>D++ Library version 10.0.5</a><a href='/10.0.4/'>D++ Library version 10.0.4</a><a href='/10.0.3/'>D++ Library version 10.0.3</a><a href='/10.0.2/'>D++ Library version 10.0.2</a><a href='/10.0.1/'>D++ Library version 10.0.1</a><a href='/10.0.0/'>D++ Library version 10.0.0</a><a href='/9.0.19/'>D++ Library version 9.0.19</a><a href='/9.0.18/'>D++ Library version 9.0.18</a><a href='/9.0.17/'>D++ Library version 9.0.17</a><a href='/9.0.16/'>D++ Library version 9.0.16</a><a href='/9.0.15/'>D++ Library version 9.0.15</a><a href='/9.0.14/'>D++ Library version 9.0.14</a><a href='/9.0.13/'>D++ Library version 9.0.13</a><a href='/9.0.12/'>D++ Library version 9.0.12</a><a href='/9.0.11/'>D++ Library version 9.0.11</a><a href='/9.0.10/'>D++ Library version 9.0.10</a><a href='/9.0.9/'>D++ Library version 9.0.9</a><a href='/9.0.8/'>D++ Library version 9.0.8</a><a href='/9.0.7/'>D++ Library version 9.0.7</a><a href='/9.0.6/'>D++ Library version 9.0.6</a><a href='/9.0.5/'>D++ Library version 9.0.5</a><a href='/9.0.4/'>D++ Library version 9.0.4</a><a href='/9.0.3/'>D++ Library version 9.0.3</a><a href='/9.0.2/'>D++ Library version 9.0.2</a><a href='/9.0.1/'>D++ Library version 9.0.1</a><a href='/9.0.0/'>D++ Library version 9.0.0</a><a href='/1.0.2/'>D++ Library version 1.0.2</a><a href='/1.0.1/'>D++ Library version 1.0.1</a><a href='/1.0.0/'>D++ Library version 1.0.0</a>
</div>
</body>
</html>