@@ -122,11 +122,11 @@ func (c *lookupResultCache) cleanup(mctx libkb.MetaContext) {
122122 }
123123}
124124
125- func (c * CachedContactsProvider ) getCache (mctx libkb.MetaContext ) lookupResultCache {
125+ func (s * ContactCacheStore ) getCache (mctx libkb.MetaContext ) ( obj lookupResultCache , created bool ) {
126126 var conCache lookupResultCache
127127 var createCache bool
128- cacheKey := c . Store .dbKey (mctx .CurrentUID ())
129- found , err := c . Store .encryptedDB .Get (mctx .Ctx (), cacheKey , & conCache )
128+ cacheKey := s .dbKey (mctx .CurrentUID ())
129+ found , err := s .encryptedDB .Get (mctx .Ctx (), cacheKey , & conCache )
130130 if err != nil {
131131 mctx .Warning ("Unable to pull contact lookup cache: %s" , err )
132132 createCache = true
@@ -143,12 +143,17 @@ func (c *CachedContactsProvider) getCache(mctx libkb.MetaContext) lookupResultCa
143143 if createCache {
144144 conCache = newLookupResultCache ()
145145 }
146- return conCache
146+ return conCache , createCache
147147}
148148
149- func (c * CachedContactsProvider ) CleanCache (mctx libkb.MetaContext ) error {
150- cacheKey := c .Store .dbKey (mctx .CurrentUID ())
151- return c .Store .encryptedDB .Delete (mctx .Ctx (), cacheKey )
149+ func (s * ContactCacheStore ) putCache (mctx libkb.MetaContext , cacheObj lookupResultCache ) error {
150+ cacheKey := s .dbKey (mctx .CurrentUID ())
151+ return s .encryptedDB .Put (mctx .Ctx (), cacheKey , cacheObj )
152+ }
153+
154+ func (s * ContactCacheStore ) ClearCache (mctx libkb.MetaContext ) error {
155+ cacheKey := s .dbKey (mctx .CurrentUID ())
156+ return s .encryptedDB .Delete (mctx .Ctx (), cacheKey )
152157}
153158
154159func (c * CachedContactsProvider ) LookupAll (mctx libkb.MetaContext , emails []keybase1.EmailAddress ,
@@ -171,7 +176,7 @@ func (c *CachedContactsProvider) LookupAll(mctx libkb.MetaContext, emails []keyb
171176 c .lock .Lock ()
172177 defer c .lock .Unlock ()
173178
174- conCache := c .getCache (mctx )
179+ conCache , _ := c . Store .getCache (mctx )
175180
176181 var remainingEmails []keybase1.EmailAddress
177182 var remainingNumbers []keybase1.RawPhoneNumber
@@ -234,9 +239,7 @@ func (c *CachedContactsProvider) LookupAll(mctx libkb.MetaContext, emails []keyb
234239 }
235240
236241 conCache .cleanup (mctx )
237-
238- cacheKey := c .Store .dbKey (mctx .CurrentUID ())
239- cerr := c .Store .encryptedDB .Put (mctx .Ctx (), cacheKey , conCache )
242+ cerr := c .Store .putCache (mctx , conCache )
240243 if cerr != nil {
241244 mctx .Warning ("Unable to update cache: %s" , cerr )
242245 }
@@ -252,3 +255,28 @@ func (c *CachedContactsProvider) FindUsernames(mctx libkb.MetaContext, uids []ke
252255func (c * CachedContactsProvider ) FindFollowing (mctx libkb.MetaContext , uids []keybase1.UID ) (map [keybase1.UID ]bool , error ) {
253256 return c .Provider .FindFollowing (mctx , uids )
254257}
258+
259+ // RemoveContactsCachePhoneEntry removes cached lookup for phone number.
260+ func (s * ContactCacheStore ) RemoveContactsCacheEntries (mctx libkb.MetaContext ,
261+ phone * keybase1.PhoneNumber , email * keybase1.EmailAddress ) {
262+ // TODO: Use a phoneNumber | email variant instead of two pointers.
263+ cacheObj , created := s .getCache (mctx )
264+ if created {
265+ // There was no cache.
266+ return
267+ }
268+ if phone != nil {
269+ // TODO: this type conversion shouldn't have to be here,
270+ // since this cache should take `PhoneNumber`s.
271+ delete (cacheObj .Lookups , MakePhoneLookupKey (keybase1 .RawPhoneNumber (* phone )))
272+ mctx .Debug ("ContactCacheStore: Removing phone number %q from lookup cache" , * phone )
273+ }
274+ if email != nil {
275+ delete (cacheObj .Lookups , MakeEmailLookupKey (* email ))
276+ mctx .Debug ("ContactCacheStore: Removing email %q from lookup cache" , * email )
277+ }
278+ err := s .putCache (mctx , cacheObj )
279+ if err != nil {
280+ mctx .Warning ("ContactCacheStore: Unable to update cache: %s" , err )
281+ }
282+ }
0 commit comments