Skip to content

Commit 023a952

Browse files
committed
LRUExists, LRUDelete, LRUPurge code example update
1 parent 0e1d317 commit 023a952

File tree

10 files changed

+238
-9
lines changed

10 files changed

+238
-9
lines changed

dist/js/dyCache.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.html

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,6 +1462,32 @@ <h4><code>LRUInit(name, size)</code></h4>
14621462

14631463
<hr>
14641464

1465+
<!-- LRUExists() -->
1466+
<a name="LRUExists"></a>
1467+
<h4><code>LRUExists(name)</code></h4>
1468+
1469+
<p>This will check if the LRU object
1470+
referred by <code>name</code> exists in the cache.</p>
1471+
1472+
<p>Returns <code>true</code> on success, <code>false</code> otherwise.</p>
1473+
1474+
<pre><code>obj.LRUExists('myLRU');</code></pre>
1475+
1476+
<div>
1477+
<a class="btn btn-primary"
1478+
role="button"
1479+
data-toggle="collapse"
1480+
href="#collapse-LRUExists"
1481+
aria-expanded="false"
1482+
aria-controls="collapse-LRUExists">Output</a>
1483+
</div>
1484+
<div class="collapse" id="collapse-LRUExists">
1485+
</div>
1486+
1487+
<!-- LRUExists() ends here -->
1488+
1489+
<hr>
1490+
14651491
<!-- LRUSet() -->
14661492
<a name="LRUSet"></a>
14671493
<h4><code>LRUSet(name, key, value)</code></h4>
@@ -1526,6 +1552,58 @@ <h4><code>LRUGet(name, key)</code></h4>
15261552

15271553
<hr>
15281554

1555+
<!-- LRUPurge() -->
1556+
<a name="LRUPurge"></a>
1557+
<h4><code>LRUPurge(name)</code></h4>
1558+
1559+
<p>This will purge the LRU object
1560+
referred by <code>name</code> in the cache.</p>
1561+
1562+
<p>Returns <code>true</code> on success, <code>false</code> otherwise.</p>
1563+
1564+
<pre><code>obj.LRUPurge('myLRU');</code></pre>
1565+
1566+
<div>
1567+
<a class="btn btn-primary"
1568+
role="button"
1569+
data-toggle="collapse"
1570+
href="#collapse-LRUPurge"
1571+
aria-expanded="false"
1572+
aria-controls="collapse-LRUPurge">Output</a>
1573+
</div>
1574+
<div class="collapse" id="collapse-LRUPurge">
1575+
</div>
1576+
1577+
<!-- LRUPurge() ends here -->
1578+
1579+
<hr>
1580+
1581+
<!-- LRUDelete() -->
1582+
<a name="LRUDelete"></a>
1583+
<h4><code>LRUDelete(name)</code></h4>
1584+
1585+
<p>This will delete the LRU object
1586+
referred by <code>name</code> from the cache.</p>
1587+
1588+
<p>Returns <code>true</code> on success, <code>false</code> otherwise.</p>
1589+
1590+
<pre><code>obj.LRUDelete('myLRU');</code></pre>
1591+
1592+
<div>
1593+
<a class="btn btn-primary"
1594+
role="button"
1595+
data-toggle="collapse"
1596+
href="#collapse-LRUDelete"
1597+
aria-expanded="false"
1598+
aria-controls="collapse-LRUDelete">Output</a>
1599+
</div>
1600+
<div class="collapse" id="collapse-LRUDelete">
1601+
</div>
1602+
1603+
<!-- LRUDelete() ends here -->
1604+
1605+
<hr>
1606+
15291607

15301608
</div>
15311609

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dycachejs",
3-
"version": "1.6.2",
3+
"version": "1.6.3",
44
"description": "Cache data using JavaScript in the browser.",
55
"main": "index.html",
66
"scripts": {

src/js/dyCache.forTest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ var dyCache = /** @class */ (function () {
845845
* @returns {boolean}
846846
*/
847847
dyCache.prototype.LRUDelete = function (name) {
848-
// if LRU object referred by 'name does not exists
848+
// if LRU object referred by 'name' does not exists
849849
// then return false
850850
if (!this.exists(name)) {
851851
return false;

src/js/dyCache.forTest.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/js/dyCache.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ var dyCache = /** @class */ (function () {
845845
* @returns {boolean}
846846
*/
847847
dyCache.prototype.LRUDelete = function (name) {
848-
// if LRU object referred by 'name does not exists
848+
// if LRU object referred by 'name' does not exists
849849
// then return false
850850
if (!this.exists(name)) {
851851
return false;

src/js/index-page-example.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,10 @@ obj.LRUInit('myLRU');
380380
output("Content of the cache.", 'collapse-LRUInit');
381381
outputJSON(obj, 'collapse-LRUInit');
382382

383+
// LRUExists();
384+
output("This will return <code>true</code> if LRU object referred by <code>myLRU</code> exists in the cache.", 'collapse-LRUExists');
385+
outputJSON(obj.LRUExists('myLRU'), 'collapse-LRUExists');
386+
383387
// LRUSet();
384388
output("This will set 3 key-value pairs in the LRU object referred by <code>myLRU</code> in the cache.", 'collapse-LRUSet');
385389
obj.LRUSet("myLRU", "k1", 10);
@@ -396,3 +400,16 @@ outputJSON(obj.LRUGet("myLRU", "k1"), 'collapse-LRUGet');
396400
output("Content of the cache after <code>LRUGet</code> operation.", 'collapse-LRUGet');
397401
outputJSON(obj, 'collapse-LRUGet');
398402
output("Note! 'k1' is moved from last index to 0th index in the queue after <code>LRUGet</code> operation.", 'collapse-LRUGet');
403+
404+
// LRUPurge();
405+
output("Content of the cache before <code>LRUPurge</code> operation.", 'collapse-LRUPurge');
406+
outputJSON(obj, 'collapse-LRUPurge');
407+
obj.LRUPurge('myLRU');
408+
output("Content of the cache after <code>LRUPurge</code> operation.", 'collapse-LRUPurge');
409+
outputJSON(obj, 'collapse-LRUPurge');
410+
411+
// LRUDelete();
412+
output("This will return <code>true</code> after deleting LRU object referred by <code>myLRU</code> from the cache.", 'collapse-LRUDelete');
413+
outputJSON(obj.LRUDelete('myLRU'), 'collapse-LRUDelete');
414+
output("Content of the cache after <code>LRUDelete</code> operation.", 'collapse-LRUDelete');
415+
outputJSON(obj, 'collapse-LRUDelete');

src/js/test.web.js

Lines changed: 104 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1126,7 +1126,7 @@ describe('Testing dyCacheJS', function () {
11261126

11271127
});
11281128

1129-
describe('Testing LRUSet()', () => {
1129+
describe('Testing LRUGet()', () => {
11301130

11311131
it('should return key-value pair when fetching "k1" key from the LRU referred by myLRU in the cache', function () {
11321132

@@ -1199,6 +1199,109 @@ describe('Testing dyCacheJS', function () {
11991199

12001200
});
12011201

1202+
describe('Testing LRUPurge()', () => {
1203+
1204+
it('should purge LRU referred by myLRU in the cache', function () {
1205+
1206+
let expected = {
1207+
"myLRU": {
1208+
"_size": 10,
1209+
"_data": {},
1210+
"_queue": []
1211+
}
1212+
};
1213+
1214+
// init
1215+
obj.LRUInit('myLRU', 10);
1216+
1217+
// set data
1218+
obj.LRUSet('myLRU', 'k1', 10);
1219+
1220+
// purge
1221+
obj.LRUPurge('myLRU');
1222+
1223+
assert.deepEqual(obj._cache, expected);
1224+
1225+
});
1226+
1227+
it('should return true on successful purge of LRU referred by myLRU in the cache', function () {
1228+
1229+
// init
1230+
obj.LRUInit('myLRU', 10);
1231+
1232+
// set data
1233+
obj.LRUSet('myLRU', 'k1', 10);
1234+
1235+
// purge
1236+
assert.isTrue(obj.LRUPurge('myLRU'));
1237+
1238+
});
1239+
1240+
it('should return false if LRU does not exists in the cache', function () {
1241+
1242+
let result = obj.LRUPurge('unknownLRU');
1243+
assert.isFalse(result);
1244+
1245+
});
1246+
1247+
});
1248+
1249+
describe('Testing LRUDelete()', () => {
1250+
1251+
it('should delete LRU referred by myLRU in the cache', function () {
1252+
1253+
// init
1254+
obj.LRUInit('myLRU', 3);
1255+
1256+
// set data
1257+
obj.LRUSet('myLRU', 'k1', 10);
1258+
1259+
// delete
1260+
obj.LRUDelete('myLRU');
1261+
1262+
assert.isFalse(obj.exists('myLRU'));
1263+
1264+
});
1265+
1266+
it('should return true after deleting LRU referred by myLRU in the cache', function () {
1267+
1268+
// init
1269+
obj.LRUInit('myLRU', 3);
1270+
1271+
// set data
1272+
obj.LRUSet('myLRU', 'k1', 10);
1273+
1274+
// delete
1275+
assert.isTrue(obj.LRUDelete('myLRU'));
1276+
1277+
});
1278+
1279+
it('should return false if trying to delete LRU that does not exists in the cache', function () {
1280+
1281+
let result = obj.LRUDelete('unknownLRU');
1282+
assert.isFalse(result);
1283+
1284+
});
1285+
1286+
});
1287+
1288+
describe('Testing LRUExists()', () => {
1289+
1290+
it('should return true if LRU referred by myLRU exists in the cache', function () {
1291+
1292+
obj.LRUInit('myLRU', 3);
1293+
assert.isTrue(obj.LRUExists('myLRU'));
1294+
1295+
});
1296+
1297+
it('should return false if LRU does not exists in the cache', function () {
1298+
1299+
assert.isFalse(obj.LRUExists('unknownLRU'));
1300+
1301+
});
1302+
1303+
});
1304+
12021305
});
12031306

12041307
});

src/ts/dyCache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,7 @@ class dyCache {
967967
*/
968968
public LRUDelete(name: string): boolean {
969969

970-
// if LRU object referred by 'name does not exists
970+
// if LRU object referred by 'name' does not exists
971971
// then return false
972972
if (!this.exists(name)) {
973973
return false;

0 commit comments

Comments
 (0)