iOS の HTTP キャッシュについて

iOS の HTTP キャッシュについて

potatotips #55 (iOS/Android開発Tips共有会)
https://potatotips.connpass.com/event/100763/

5eee847529e8f5ec2f634a85075fd5aa?s=128

Satoshi Hachiya

October 09, 2018
Tweet

Transcript

  1. iOS ͷ HTTP Ωϟογϡʹ͍ͭͯ 2018.10.9 - potatotips #55 Satoshi Hachiya

    (@jpmartha_jp)
  2. Satoshi Hachiya (@jpmartha_jp)

  3. ࠓ೔ͷ࿩ • API ͷϨεϙϯεͰߋ৽಺༰͕͙͢ʹ͸൓ө͞Εͳ͔ͬͨ • iOS ଆͷܿനΛূ໌͢ΔͨΊʹࢼͨ͠খωλ • ͙͢࢖͏Α͏ͳωλͰ͸ͳ͍͕Կ͔͋ͬͨͱ͖ͷࢀߟʹ

  4. HTTP Ωϟογϡ https://developer.mozilla.org/ja/docs/Web/HTTP/Caching ʮաڈʹऔಘͨ͠ϦιʔεΛ࠶࢖༻͢Δͱɺ΢ΣϒαΠτ΍Ξϓ ϦέʔγϣϯͷύϑΥʔϚϯε͕େ͖͘޲্͢ΔͰ͠ΐ͏ɻ΢Σ ϒΩϟογϡ͸஗Ԇ΍ωοτϫʔΫͷτϥϑΟοΫΛ࡟ݮͯ͠ɺ ϦιʔεΛදࣔ͢ΔͨΊʹඞཁͳ࣌ؒ΋୹ॖ͠·͢ɻ HTTP ΩϟογϡΛ࢖༻͢Δͱɺ΢ΣϒαΠτͷԠ౴ੑ͕ߴ·Γ· ͢ɻʯ

  5. https://developers.google.com/web/fundamentals/performance/ optimizing-content-efficiency/http-caching?hl=ja ʮωοτϫʔΫܦ༝Ͱ৘ใΛऔಘ͢Δʹ͸࣌ؒ΋ίετ΋͔͔Γ ·͢ɻϨεϙϯε͕େ͖͍ͱɺΫϥΠΞϯτͱαʔόʔؒͷϥ΢ ϯυτϦοϓΛԿ౓΋܁Γฦ͢ඞཁ͕͋ΔͨΊɺϨεϙϯε͕ར ༻Մೳͱͳͬͯϒϥ΢βͰॲཧͰ͖ΔΑ͏ʹͳΔ·Ͱ͕͔͔࣌ؒ Γ·͢ɻ͞ΒʹɺϢʔβʔଆͰ͸σʔλͷ௨৴ίετ͕ൃੜ͠· ͢ɻͦͷͨΊɺલʹऔಘͨ͠ϦιʔεΛΩϟογϡʹอଘͯ͠࠶ ࢖༻Ͱ͖Δ͜ͱ͸ɺύϑΥʔϚϯεΛ࠷దԽ͢Δ্Ͱඇৗʹॏཁ Ͱ͢ɻʯ

  6. iOS Ͱ ΩϟογϡΛಡΈࠐ·ͳ͍ํ๏͸ άάΕ͹͙͢ݟ͔ͭΔ

  7. CachePolicy Λมߋ

  8. CachePolicy Λมߋ

  9. ͪͳΈʹ .reloadIgnoringLocalAndRemoteCacheData ͸ ࣮૷͞Ε͍ͯͳ͍ʂ

  10. None
  11. ͦΕ͸͓͖ͯ͞

  12. CachePolicy ͷઃఆ͚ͩͰ͸ ΩϟογϡΛಡΈࠐ·ͳ͍͕ ! อଘ͸͢Δ

  13. γϛϡϨʔλʔͰΩϟογϡΛ֬ೝ

  14. อଘ৔ॴ /Library/Developer/CoreSimulator/Devices/xxx/data/ Containers/Data/Application/xxx/Library/Caches/ com.example.bundleid ʹ͋ͬͨ

  15. cache.db Λͷͧ͘ • DB Browser for SQLite

  16. ͜Μͳײ͡

  17. ΩϟογϡΛಡΈࠐ·ͳ͍ ʢΆ͍ʣ͠ɺ͜ΕͰΑ͘ͳ͍ʁ

  18. ΋ΕͨΒ·͍ͣΩϟογϡ͸อଘ͠ͳ͍ • ॏཁ৘ใͷ࿙͍͑ʹͭͳ͕ΔεϚϗΞϓϦͷΩϟογϡ໰୊ͱ ରࡦɿhttps://www.lac.co.jp/lacwatch/people/ 20180228_001581.html • ͨͩͪ͜͠ΒͰ঺հ͞Ε͍ͯΔํ๏ͷ͏ͪɺCapacity = 0 ͩͱ

    ͦΕҎ߱ΩϟογϡΛར༻Ͱ͖ͳ͘ͳΓͦ͏
  19. ΩϟογϡΛಡΈࠐ·ͳ͍͠ อଘ΋͠ͳ͍ํ๏

  20. None
  21. configuration.urlCache = nil

  22. ·ͨ͸ .ephemeral

  23. ͨͩ͠ɺ͍ͣΕ΋ طଘͷΩϟογϡ͸࢒Δ

  24. ΩϟογϡΛ࡟আ͢Δํ๏ ͢΂ͯ࡟আ ૂ͍ܸͪʢࣦഊʣ session.configuration.urlCache?.removeCachedResponse(for: urlRequest)

  25. None
  26. ·ͱΊ • લఏɿΩϟογϡ͸ύϑΥʔϚϯε޲্ʹඞཁ • requestCachePolicy Λมߋ͚ͨͩ͠Ͱ͸ΩϟογϡΛอଘ͢Δ • urlCache = nil

    ʹมߋͯ͠΋طଘͷΩϟογϡ͸࢒Δ ʢ.ephemeral ΋ʣ • removeAllCachedResponses Ͱ͢΂ͯ࡟আ͢Δ • Capacity = 0 ʹ͢ΔͱͦΕҎ߱ΩϟογϡΛར༻Ͱ͖ͳ͍ʁ
  27. ࢀߟ • URL Loading Systemɿhttps://developer.apple.com/ documentation/foundation/url_loading_system • Ωϟογϡͷڍಈɿhttps://developer.apple.com/ documentation/foundation/nsurlrequest/cachepolicy/ useprotocolcachepolicy

    • Ωϟογϡ΁ͷΞΫηεɿhttps://developer.apple.com/ documentation/foundation/url_loading_system/ accessing_cached_data
  28. Thanks!