nsICache.idl 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2. *
  3. * This Source Code Form is subject to the terms of the Mozilla Public
  4. * License, v. 2.0. If a copy of the MPL was not distributed with this
  5. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  6. #include "nsISupports.idl"
  7. typedef long nsCacheStoragePolicy;
  8. typedef long nsCacheAccessMode;
  9. /**
  10. * nsICache is a namespace for various cache constants. It does not represent
  11. * an actual object.
  12. */
  13. [scriptable, uuid(d6c67f38-b39a-4582-8a48-4c4f8a56dfd0)]
  14. interface nsICache
  15. {
  16. /**
  17. * Access Modes
  18. *
  19. *
  20. * Mode Requested | Not Cached | Cached
  21. * ------------------------------------------------------------------------
  22. * READ | KEY_NOT_FOUND | NS_OK
  23. * | Mode = NONE | Mode = READ
  24. * | No Descriptor | Descriptor
  25. * ------------------------------------------------------------------------
  26. * WRITE | NS_OK | NS_OK (Cache service
  27. * | Mode = WRITE | Mode = WRITE dooms existing
  28. * | Descriptor | Descriptor cache entry)
  29. * ------------------------------------------------------------------------
  30. * READ_WRITE | NS_OK | NS_OK
  31. * (1st req.) | Mode = WRITE | Mode = READ_WRITE
  32. * | Descriptor | Descriptor
  33. * ------------------------------------------------------------------------
  34. * READ_WRITE | N/A | NS_OK
  35. * (Nth req.) | | Mode = READ
  36. * | | Descriptor
  37. * ------------------------------------------------------------------------
  38. *
  39. *
  40. * Access Requested:
  41. *
  42. * READ - I only want to READ, if there isn't an entry just fail
  43. * WRITE - I have something new I want to write into the cache, make
  44. * me a new entry and doom the old one, if any.
  45. * READ_WRITE - I want to READ, but I'm willing to update an existing
  46. * entry if necessary, or create a new one if none exists.
  47. *
  48. *
  49. * Access Granted:
  50. *
  51. * NONE - No descriptor is provided. You get zilch. Nada. Nothing.
  52. * READ - You can READ from this descriptor.
  53. * WRITE - You must WRITE to this descriptor because the cache entry
  54. * was just created for you.
  55. * READ_WRITE - You can READ the descriptor to determine if it's valid,
  56. * you may WRITE if it needs updating.
  57. *
  58. *
  59. * Comments:
  60. *
  61. * If you think that you might need to modify cached data or meta data,
  62. * then you must open a cache entry requesting WRITE access. Only one
  63. * cache entry descriptor, per cache entry, will be granted WRITE access.
  64. *
  65. * Usually, you will request READ_WRITE access in order to first test the
  66. * meta data and informational fields to determine if a write (ie. going
  67. * to the net) may actually be necessary. If you determine that it is
  68. * not, then you would mark the cache entry as valid (using MarkValid) and
  69. * then simply read the data from the cache.
  70. *
  71. * A descriptor granted WRITE access has exclusive access to the cache
  72. * entry up to the point at which it marks it as valid. Once the cache
  73. * entry has been "validated", other descriptors with READ access may be
  74. * opened to the cache entry.
  75. *
  76. * If you make a request for READ_WRITE access to a cache entry, the cache
  77. * service will downgrade your access to READ if there is already a
  78. * cache entry descriptor open with WRITE access.
  79. *
  80. * If you make a request for only WRITE access to a cache entry and another
  81. * descriptor with WRITE access is currently open, then the existing cache
  82. * entry will be 'doomed', and you will be given a descriptor (with WRITE
  83. * access only) to a new cache entry.
  84. *
  85. */
  86. const nsCacheAccessMode ACCESS_NONE = 0;
  87. const nsCacheAccessMode ACCESS_READ = 1;
  88. const nsCacheAccessMode ACCESS_WRITE = 2;
  89. const nsCacheAccessMode ACCESS_READ_WRITE = 3;
  90. /**
  91. * Storage Policy
  92. *
  93. * The storage policy of a cache entry determines the device(s) to which
  94. * it belongs. See nsICacheSession and nsICacheEntryDescriptor for more
  95. * details.
  96. *
  97. * STORE_ANYWHERE - Allows the cache entry to be stored in any device.
  98. * The cache service decides which cache device to use
  99. * based on "some resource management calculation."
  100. * STORE_IN_MEMORY - Requires the cache entry to reside in non-persistent
  101. * storage (ie. typically in system RAM).
  102. * STORE_ON_DISK - Requires the cache entry to reside in persistent
  103. * storage (ie. typically on a system's hard disk).
  104. * STORE_OFFLINE - Requires the cache entry to reside in persistent,
  105. * reliable storage for offline use.
  106. */
  107. const nsCacheStoragePolicy STORE_ANYWHERE = 0;
  108. const nsCacheStoragePolicy STORE_IN_MEMORY = 1;
  109. const nsCacheStoragePolicy STORE_ON_DISK = 2;
  110. // value 3 was used by STORE_ON_DISK_AS_FILE which was removed
  111. const nsCacheStoragePolicy STORE_OFFLINE = 4;
  112. /**
  113. * All entries for a cache session are stored as streams of data or
  114. * as objects. These constant my be used to specify the type of entries
  115. * when calling nsICacheService::CreateSession().
  116. */
  117. const long NOT_STREAM_BASED = 0;
  118. const long STREAM_BASED = 1;
  119. /**
  120. * The synchronous OpenCacheEntry() may be blocking or non-blocking. If a cache entry is
  121. * waiting to be validated by another cache descriptor (so no new cache descriptors for that
  122. * key can be created, OpenCacheEntry() will return NS_ERROR_CACHE_WAIT_FOR_VALIDATION in
  123. * non-blocking mode. In blocking mode, it will wait until the cache entry for the key has
  124. * been validated or doomed. If the cache entry is validated, then a descriptor for that
  125. * entry will be created and returned. If the cache entry was doomed, then a descriptor
  126. * will be created for a new cache entry for the key.
  127. */
  128. const long NON_BLOCKING = 0;
  129. const long BLOCKING = 1;
  130. /**
  131. * Constant meaning no expiration time.
  132. */
  133. const unsigned long NO_EXPIRATION_TIME = 0xFFFFFFFF;
  134. };