@@ -195,17 +195,17 @@ func (c *localCache) GetActive(k Key) (Value, error) {
195195 return nil , err
196196 }
197197 en := c .cache .get (k , sum (k ))
198- if en != nil && ! en .getInvalidated () {
198+ if en != nil && ! en .getInvalidated () {
199199 return obj , nil
200200 }
201- return nil , errors .New ("entry invalidated" )
201+ return nil , errors .New ("entry invalidated" )
202202}
203203
204204// GetAllKeys returns all keys.
205205func (c * localCache ) GetAllKeys () []interface {} {
206206 keys := make ([]interface {}, 0 , c .cache .len ())
207207 c .cache .walk (func (en * entry ) {
208- if ! en .getInvalidated () {
208+ if ! en .getInvalidated () {
209209 keys = append (keys , en .key )
210210 }
211211 })
@@ -216,7 +216,7 @@ func (c *localCache) GetAllKeys() []interface{} {
216216func (c * localCache ) GetAllValues () []interface {} {
217217 values := make ([]interface {}, 0 , c .cache .len ())
218218 c .cache .walk (func (en * entry ) {
219- if ! en .getInvalidated () {
219+ if ! en .getInvalidated () {
220220 values = append (values , en .getValue ())
221221 }
222222 })
@@ -227,7 +227,7 @@ func (c *localCache) GetAllValues() []interface{} {
227227func (c * localCache ) GetAll () map [interface {}]interface {} {
228228 var values = make (map [interface {}]interface {}, c .cache .len ())
229229 c .cache .walk (func (en * entry ) {
230- if ! en .getInvalidated () {
230+ if ! en .getInvalidated () {
231231 values [en .key ] = en .getValue ()
232232 }
233233 })
@@ -253,6 +253,24 @@ func (c *localCache) Refresh(k Key) {
253253 }
254254}
255255
256+ // RefreshIfModifiedAfter asynchronously reloads value for Key if the provided timestamp
257+ // indicates the data was modified after the entry was last loaded. If the entry doesn't exist,
258+ // it will synchronously load and block until the value is loaded.
259+ func (c * localCache ) RefreshIfModifiedAfter (k Key , modifiedTime time.Time ) {
260+ if c .loader == nil {
261+ return
262+ }
263+ en := c .cache .get (k , sum (k ))
264+ if en == nil {
265+ c .load (k )
266+ } else {
267+ // Only refresh if the data was modified after the entry was last loaded
268+ if modifiedTime .UnixNano () > en .getWriteTime () {
269+ c .refreshAsync (en )
270+ }
271+ }
272+ }
273+
256274// Stats copies cache stats to t.
257275func (c * localCache ) Stats (t * Stats ) {
258276 c .stats .Snapshot (t )
0 commit comments