Flutter के लिए Dio HTTP कैश लाइब्रेरी, RxCache के समान। यह डिस्क कैश के रूप में sqflite का उपयोग करता है, और मेमोरी कैश के लिए google/quiver-dart/LRU रणनीति का उपयोग करता है।
सार्वजनिक जानकारी से बना चयन मार्गदर्शन। केवल संदर्भ हेतु।
Dio HTTP Cache फ्लटर के डियो HTTP क्लाइंट के लिए एक कैशिंग लाइब्रेरी है, जो मेमोरी और डिस्क-आधारित कैशिंग दोनों प्रदान करती है। यह स्थायी स्टोरेज के लिए sqflite का उपयोग करती है और google/quiver-dart के माध्यम से LRU (सबसे कम हाल ही में उपयोग किया गया) रणनीति को लागू करती है, जिससे सुदृढ़ मेमोरी प्रबंधन होता है। यह पैकेज HTTP प्रतिक्रियाओं को कैश करके अनावश्यक नेटवर्क अनुरोधों को कम करने, ऐप प्रदर्शन में सुधार करने और बैंडविड्थ बचाने में मदद करता है। ऑफलाइन समर्थन या स्थिर डेटा के साथ आवर्ती API कॉल की आवश्यकता वाले ऐप्स के लिए आदर्श है।
उपयोग
नेटवर्क उपयोग कम करने के लिए API प्रतिक्रियाओं को कैश करें
पहले डाउनलोड किए गए डेटा तक ऑफ़लाइन पहुंच सक्षम करना
कम लेटेंसी के साथ ऐप प्रदर्शन में सुधार
अक्सर एक्सेस किए गए डेटा को कुशलतापूर्वक संग्रहीत करना
कैश किए गए प्रतिक्रियाओं के माध्यम से सर्वर लोड को कम करना
मुख्य विशेषताएँ
sqflite का उपयोग करके डिस्क कैशिंग
LRU मेमोरी कैश, quiver-dart के साथ
स्वचालित अनुरोध/प्रतिक्रिया कैशिंग
कॉन्फ़िगरेबल कैश एक्सपायर
GET और HEAD अनुरोधों का समर्थन करता है
इनके लिए उपयुक्त
आवेदन जिनमें अक्सर API कॉल होते हैं
ऑफलाइन-क्षम एप्लिकेशन
प्रदर्शन-अनुकूलित नेटवर्क परतें
डेटा-भारी मोबाइल ऐप्स
HTTP रिक्वेस्ट के लिए Dio का उपयोग करने वाले डेवलपर्स
विचार योग्य बातें
sqflite सेटअप और अनुमतियों की आवश्यकता है
कैश आकार को हस्तचालित रूप से प्रबंधित करना आवश्यक है
बड़े बाइनरी डेटा के लिए उपयुक्त नहीं
GET/HEAD विधियों तक सीमित
जटिल अनुरोधों के लिए कस्टम कैश की तारीख तारीख की आवश्यकता हो सकती है
मूल README
संबंधित सोर्स रिपॉज़िटरी के मूल README का स्नैपशॉट। नवीनतम सामग्री के लिए रिपॉज़िटरी देखें।
If getting data from network succeeds, store or refresh cache.
If getting data from network fails or no network avaliable, try get data from cache instead of an error.
Use "CacheConfig" to config default params
baseUrl: it’s optional; If you don't have set baseUrl in CacheConfig, when you call deleteCache, you need provide full path like "https://www.google.com/search?q=hello", but not just "search?q=hello".
encrypt / decrypt: these two must be used together to encrypt the disk cache data, you can also zip data here.
defaultMaxAge: use Duration(day:7) as default.
defaultaMaxStale: similar with DefaultMaxAge.
databasePath: database path.
databaseName: database name.
skipMemoryCache: false defalut.
skipDiskCache: false default.
maxMemoryCacheCount: 100 defalut.
defaultRequestMethod: use "POST" as default, it will be used in delete caches.
diskStore: custom disk storage.
How to clear expired cache
Just ignore it, that is automatic.
But if you insist : DioCacheManager.clearExpired();
How to delete caches
No matter what subKey is, delete local cache if primary matched.
// Automatically parses primarykey from path
_dioCacheManager.deleteByPrimaryKey(path, requestMethod: "POST");
Delete local cache when both primaryKey and subKey matched.
// delete local cache when both primaryKey and subKey matched.
_dioCacheManager.deleteByPrimaryKeyAndSubKey(path, requestMethod: "GET");
INPORTANT: If you have additional parameters when requesting the http interface, you must take them with it, for example:
0 ~ 3 days : Return data from cache directly (irrelevant with network).
3 ~ 7 days:
Get data from network first.
If getting data from network succeeds, refresh cache.
If getting data from network fails or no network avaliable, try get data from cache instead of an error.
7 ~ ∞ days: It won't use cache anymore, and the cache will be deleted at the right time.
License
Copyright2019HurshiLicensed under the ApacheLicense, Version2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0Unlessrequired by applicable law or agreed to in writing, software
distributed under the Licenseis distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the Licensefor the specific language governing permissions and
limitations under the License.