FSTLRUGarbageCollector.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright 2018 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. #include <string>
  18. #include <unordered_map>
  19. #include "Firestore/core/src/firebase/firestore/api/settings.h"
  20. #include "Firestore/core/src/firebase/firestore/local/query_cache.h"
  21. #include "Firestore/core/src/firebase/firestore/local/query_data.h"
  22. #include "Firestore/core/src/firebase/firestore/model/document_key.h"
  23. #include "Firestore/core/src/firebase/firestore/model/types.h"
  24. namespace firebase {
  25. namespace firestore {
  26. namespace local {
  27. class LruGarbageCollector;
  28. } // namespace local
  29. } // namespace firestore
  30. } // namespace firebase
  31. namespace local = firebase::firestore::local;
  32. namespace model = firebase::firestore::model;
  33. /**
  34. * Persistence layers intending to use LRU Garbage collection should implement this protocol. This
  35. * protocol defines the operations that the LRU garbage collector needs from the persistence layer.
  36. */
  37. @protocol FSTLRUDelegate
  38. /**
  39. * Enumerates all the targets that the delegate is aware of. This is typically all of the targets in
  40. * an FSTQueryCache.
  41. */
  42. - (void)enumerateTargetsUsingCallback:(const local::TargetCallback &)callback;
  43. /**
  44. * Enumerates all of the outstanding mutations.
  45. */
  46. - (void)enumerateMutationsUsingCallback:(const local::OrphanedDocumentCallback &)callback;
  47. /**
  48. * Removes all unreferenced documents from the cache that have a sequence number less than or equal
  49. * to the given sequence number. Returns the number of documents removed.
  50. */
  51. - (int)removeOrphanedDocumentsThroughSequenceNumber:(model::ListenSequenceNumber)sequenceNumber;
  52. /**
  53. * Removes all targets that are not currently being listened to and have a sequence number less than
  54. * or equal to the given sequence number. Returns the number of targets removed.
  55. */
  56. - (int)removeTargetsThroughSequenceNumber:(model::ListenSequenceNumber)sequenceNumber
  57. liveQueries:
  58. (const std::unordered_map<model::TargetId, local::QueryData> &)
  59. liveQueries;
  60. - (size_t)byteSize;
  61. /** Returns the number of targets and orphaned documents cached. */
  62. - (size_t)sequenceNumberCount;
  63. /** Access to the underlying LRU Garbage collector instance. */
  64. - (local::LruGarbageCollector *)gc;
  65. @end