@@ -61,7 +61,7 @@ Storage_.prototype.getValue = function(key, optSkipMemoryCheck) {
6161
6262 if ( ! optSkipMemoryCheck ) {
6363 // Check in-memory cache.
64- if ( value = this . memory_ [ key ] ) {
64+ if ( value = this . memory_ [ prefixedKey ] ) {
6565 if ( value === Storage_ . CACHE_NULL_VALUE ) {
6666 return null ;
6767 }
@@ -72,7 +72,7 @@ Storage_.prototype.getValue = function(key, optSkipMemoryCheck) {
7272 // Check cache.
7373 if ( this . cache_ && ( jsonValue = this . cache_ . get ( prefixedKey ) ) ) {
7474 value = JSON . parse ( jsonValue ) ;
75- this . memory_ [ key ] = value ;
75+ this . memory_ [ prefixedKey ] = value ;
7676 if ( value === Storage_ . CACHE_NULL_VALUE ) {
7777 return null ;
7878 }
@@ -87,13 +87,13 @@ Storage_.prototype.getValue = function(key, optSkipMemoryCheck) {
8787 jsonValue , Storage_ . CACHE_EXPIRATION_TIME_SECONDS ) ;
8888 }
8989 value = JSON . parse ( jsonValue ) ;
90- this . memory_ [ key ] = value ;
90+ this . memory_ [ prefixedKey ] = value ;
9191 return value ;
9292 }
9393
9494 // Not found. Store a special null value in the memory and cache to reduce
9595 // hits on the PropertiesService.
96- this . memory_ [ key ] = Storage_ . CACHE_NULL_VALUE ;
96+ this . memory_ [ prefixedKey ] = Storage_ . CACHE_NULL_VALUE ;
9797 if ( this . cache_ ) {
9898 this . cache_ . put ( prefixedKey , JSON . stringify ( Storage_ . CACHE_NULL_VALUE ) ,
9999 Storage_ . CACHE_EXPIRATION_TIME_SECONDS ) ;
@@ -116,7 +116,7 @@ Storage_.prototype.setValue = function(key, value) {
116116 this . cache_ . put ( prefixedKey , jsonValue ,
117117 Storage_ . CACHE_EXPIRATION_TIME_SECONDS ) ;
118118 }
119- this . memory_ [ key ] = value ;
119+ this . memory_ [ prefixedKey ] = value ;
120120} ;
121121
122122/**
@@ -125,13 +125,39 @@ Storage_.prototype.setValue = function(key, value) {
125125 */
126126Storage_ . prototype . removeValue = function ( key ) {
127127 var prefixedKey = this . getPrefixedKey_ ( key ) ;
128+ this . removeValueWithPrefixedKey_ ( prefixedKey ) ;
129+ } ;
130+
131+ /**
132+ * Resets the storage, removing all stored data.
133+ * @param {string } key The key.
134+ */
135+ Storage_ . prototype . reset = function ( ) {
136+ var prefix = this . getPrefixedKey_ ( ) ;
137+ var prefixedKeys = Object . keys ( this . memory_ ) ;
138+ if ( this . properties_ ) {
139+ var props = this . properties_ . getProperties ( ) ;
140+ prefixedKeys = Object . keys ( props ) . filter ( function ( prefixedKey ) {
141+ return prefixedKey === prefix || prefixedKey . indexOf ( prefix + '.' ) === 0 ;
142+ } ) ;
143+ }
144+ for ( var i = 0 ; i < prefixedKeys . length ; i ++ ) {
145+ this . removeValueWithPrefixedKey_ ( prefixedKeys [ i ] ) ;
146+ } ;
147+ } ;
148+
149+ /**
150+ * Removes a stored value.
151+ * @param {string } key The key.
152+ */
153+ Storage_ . prototype . removeValueWithPrefixedKey_ = function ( prefixedKey ) {
128154 if ( this . properties_ ) {
129155 this . properties_ . deleteProperty ( prefixedKey ) ;
130156 }
131157 if ( this . cache_ ) {
132158 this . cache_ . remove ( prefixedKey ) ;
133159 }
134- delete this . memory_ [ key ] ;
160+ delete this . memory_ [ prefixedKey ] ;
135161} ;
136162
137163/**
0 commit comments