FSTRemoteDocumentCache.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. @class FSTDocumentKey;
  19. @class FSTMaybeDocument;
  20. @class FSTQuery;
  21. @class FSTWriteGroup;
  22. NS_ASSUME_NONNULL_BEGIN
  23. /**
  24. * Represents cached documents received from the remote backend.
  25. *
  26. * The cache is keyed by FSTDocumentKey and entries in the cache are FSTMaybeDocument instances,
  27. * meaning we can cache both FSTDocument instances (an actual document with data) as well as
  28. * FSTDeletedDocument instances (indicating that the document is known to not exist).
  29. */
  30. @protocol FSTRemoteDocumentCache <NSObject>
  31. /** Shuts this cache down, closing open files, etc. */
  32. - (void)shutdown;
  33. /**
  34. * Adds or replaces an entry in the cache.
  35. *
  36. * The cache key is extracted from `maybeDocument.key`. If there is already a cache entry for
  37. * the key, it will be replaced.
  38. *
  39. * @param maybeDocument A FSTDocument or FSTDeletedDocument to put in the cache.
  40. */
  41. - (void)addEntry:(FSTMaybeDocument *)maybeDocument group:(FSTWriteGroup *)group;
  42. /** Removes the cached entry for the given key (no-op if no entry exists). */
  43. - (void)removeEntryForKey:(FSTDocumentKey *)documentKey group:(FSTWriteGroup *)group;
  44. /**
  45. * Looks up an entry in the cache.
  46. *
  47. * @param documentKey The key of the entry to look up.
  48. * @return The cached FSTDocument or FSTDeletedDocument entry, or nil if we have nothing cached.
  49. */
  50. - (nullable FSTMaybeDocument *)entryForKey:(FSTDocumentKey *)documentKey;
  51. /**
  52. * Executes a query against the cached FSTDocument entries
  53. *
  54. * Implementations may return extra documents if convenient. The results should be re-filtered
  55. * by the consumer before presenting them to the user.
  56. *
  57. * Cached FSTDeletedDocument entries have no bearing on query results.
  58. *
  59. * @param query The query to match documents against.
  60. * @return The set of matching documents.
  61. */
  62. - (FSTDocumentDictionary *)documentsMatchingQuery:(FSTQuery *)query;
  63. @end
  64. NS_ASSUME_NONNULL_END