FSTRemoteDocumentCache.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <Foundation/Foundation.h>
  17. #import "Firestore/Source/Model/FSTDocumentDictionary.h"
  18. #include "Firestore/core/src/firebase/firestore/model/document_key.h"
  19. @class FSTMaybeDocument;
  20. @class FSTQuery;
  21. NS_ASSUME_NONNULL_BEGIN
  22. /**
  23. * Represents cached documents received from the remote backend.
  24. *
  25. * The cache is keyed by FSTDocumentKey and entries in the cache are FSTMaybeDocument instances,
  26. * meaning we can cache both FSTDocument instances (an actual document with data) as well as
  27. * FSTDeletedDocument instances (indicating that the document is known to not exist).
  28. */
  29. @protocol FSTRemoteDocumentCache <NSObject>
  30. /**
  31. * Adds or replaces an entry in the cache.
  32. *
  33. * The cache key is extracted from `maybeDocument.key`. If there is already a cache entry for
  34. * the key, it will be replaced.
  35. *
  36. * @param maybeDocument A FSTDocument or FSTDeletedDocument to put in the cache.
  37. */
  38. - (void)addEntry:(FSTMaybeDocument *)maybeDocument;
  39. /** Removes the cached entry for the given key (no-op if no entry exists). */
  40. - (void)removeEntryForKey:(const firebase::firestore::model::DocumentKey &)documentKey;
  41. /**
  42. * Looks up an entry in the cache.
  43. *
  44. * @param documentKey The key of the entry to look up.
  45. * @return The cached FSTDocument or FSTDeletedDocument entry, or nil if we have nothing cached.
  46. */
  47. - (nullable FSTMaybeDocument *)entryForKey:
  48. (const firebase::firestore::model::DocumentKey &)documentKey;
  49. /**
  50. * Executes a query against the cached FSTDocument entries
  51. *
  52. * Implementations may return extra documents if convenient. The results should be re-filtered
  53. * by the consumer before presenting them to the user.
  54. *
  55. * Cached FSTDeletedDocument entries have no bearing on query results.
  56. *
  57. * @param query The query to match documents against.
  58. * @return The set of matching documents.
  59. */
  60. - (FSTDocumentDictionary *)documentsMatchingQuery:(FSTQuery *)query;
  61. @end
  62. NS_ASSUME_NONNULL_END