Cache.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. using System.Collections.Generic;
  3. using BestHTTP.Core;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. namespace BestHTTP.Examples.Helpers.Components
  7. {
  8. public class Cache : MonoBehaviour
  9. {
  10. #pragma warning disable 0649, 0169
  11. [SerializeField]
  12. private Text _count;
  13. [SerializeField]
  14. private Text _size;
  15. [SerializeField]
  16. private Button _clear;
  17. #pragma warning restore
  18. private void Start()
  19. {
  20. PluginEventHelper.OnEvent += OnPluginEvent;
  21. UpdateLabels();
  22. }
  23. private void OnDestroy()
  24. {
  25. PluginEventHelper.OnEvent -= OnPluginEvent;
  26. }
  27. private void OnPluginEvent(PluginEventInfo @event)
  28. {
  29. if (@event.Event == PluginEvents.SaveCacheLibrary)
  30. UpdateLabels();
  31. }
  32. private void UpdateLabels()
  33. {
  34. #if !BESTHTTP_DISABLE_CACHING
  35. this._count.text = BestHTTP.Caching.HTTPCacheService.GetCacheEntityCount().ToString("N0");
  36. this._size.text = BestHTTP.Caching.HTTPCacheService.GetCacheSize().ToString("N0");
  37. #else
  38. this._count.text = "0";
  39. this._size.text = "0";
  40. #endif
  41. }
  42. public void OnClearButtonClicked()
  43. {
  44. #if !BESTHTTP_DISABLE_CACHING
  45. BestHTTP.Caching.HTTPCacheService.BeginClear();
  46. #endif
  47. }
  48. }
  49. }