@@ -436,6 +436,135 @@ var dyCache = /** @class */ (function () {
436436 }
437437 return - 1 ;
438438 } ;
439+ /**
440+ * This will initialise a new stack in the cache and will refer it by key.
441+ * @param {string } key
442+ */
443+ dyCache . prototype . stackInit = function ( key ) {
444+ this . _cache [ key ] = [ ] ;
445+ } ;
446+ /**
447+ * This will create a stack in the cache and will refer it by key.
448+ *
449+ * @param {string } key
450+ * @param value
451+ */
452+ dyCache . prototype . stackPush = function ( key , value ) {
453+ // create array for the key if not exists
454+ if ( ! this . exists ( key ) ) {
455+ this . _cache [ key ] = [ ] ;
456+ }
457+ this . _cache [ key ] . push ( value ) ;
458+ } ;
459+ /**
460+ * This will pop the last element from the right side of the stack
461+ * referred by key in the cache.
462+ *
463+ * On success return the element. Otherwise undefined.
464+ *
465+ * @param {string } key
466+ * @returns {any }
467+ */
468+ dyCache . prototype . stackPop = function ( key ) {
469+ // if stack referred by the key exists in the cache
470+ if ( typeof key !== 'undefined' && typeof this . _cache [ key ] !== "undefined" ) {
471+ return this . _cache [ key ] . pop ( ) ;
472+ }
473+ return undefined ;
474+ } ;
475+ /**
476+ * This will check if stack referred by the key in the cache exists.
477+ *
478+ * On success return true. Otherwise false.
479+ *
480+ * @param {string } key
481+ * @returns {boolean }
482+ */
483+ dyCache . prototype . stackExists = function ( key ) {
484+ return typeof this . _cache [ key ] !== "undefined" ;
485+ } ;
486+ /**
487+ * This will return the last element in the stack referred by key
488+ * in the cache.
489+ *
490+ * On success return the value. Otherwise, null.
491+ *
492+ * @param {string } key
493+ * @returns {any }
494+ */
495+ dyCache . prototype . stackPeek = function ( key ) {
496+ // if stack referred by the key exists in the cache
497+ if ( typeof key !== 'undefined' && typeof this . _cache [ key ] !== "undefined" ) {
498+ // return just the element like: 10
499+ // and not in an array like: [10]
500+ return this . _cache [ key ] . slice ( - 1 ) [ 0 ] ;
501+ }
502+ return null ;
503+ } ;
504+ /**
505+ * This will return total number of elements in the stack referred by
506+ * key in the cache.
507+ *
508+ * On success return a number representing total number of elements.
509+ * Otherwise, -1.
510+ *
511+ * @param {string } key
512+ * @returns {number }
513+ */
514+ dyCache . prototype . stackLength = function ( key ) {
515+ // if stack referred by the key exists in the cache
516+ if ( typeof key !== 'undefined' && typeof this . _cache [ key ] !== "undefined" ) {
517+ return Object . keys ( this . _cache [ key ] ) . length ;
518+ }
519+ return - 1 ;
520+ } ;
521+ /**
522+ * This will return true if stack referred by key in the cache is empty.
523+ * Otherwise false.
524+ *
525+ * @param {string } key
526+ * @returns {boolean }
527+ */
528+ dyCache . prototype . stackIsEmpty = function ( key ) {
529+ // if stack referred by key does not exists then return false
530+ if ( ! this . stackExists ( key ) ) {
531+ return undefined ;
532+ }
533+ return this . stackLength ( key ) === 0 ;
534+ } ;
535+ /**
536+ * This will remove all the elements from the stack referred by key
537+ * in the cache.
538+ *
539+ * On success return true. Otherwise, false.
540+ *
541+ * @param {string } key
542+ * @returns {boolean }
543+ */
544+ dyCache . prototype . stackPurge = function ( key ) {
545+ // if stack referred by key does not exists then return false
546+ if ( ! this . stackExists ( key ) ) {
547+ return false ;
548+ }
549+ this . stackInit ( key ) ;
550+ return true ;
551+ } ;
552+ /**
553+ * This will delete the stack from the cache.
554+ *
555+ * On success return true. Otherwise false.
556+ *
557+ * @param {string } key
558+ * @returns {boolean }
559+ */
560+ dyCache . prototype . stackDelete = function ( key ) {
561+ // if stack referred by key does not exists then return false
562+ if ( ! this . stackExists ( key ) ) {
563+ return false ;
564+ }
565+ this . del ( key ) ;
566+ return true ;
567+ } ;
439568 return dyCache ;
440569} ( ) ) ;
441570
0 commit comments