Unity 웹 플랫폼에서는 캐시 API를 사용하여 .data
파일과 에셋 번들에 캐시된 에셋 데이터를 브라우저 캐시 내에 저장할 수 있습니다. 최대 파일 크기, 최대 전체 캐시 크기, 삭제 기준 등 브라우저 캐시의 스토리지 제한은 사용 중인 브라우저와 플랫폼에 따라 다릅니다. 자세한 내용은 브라우저 스토리지 제한 및 삭제 기준을 참조하십시오.
Data Caching에 액세스하려면 File > Build Settings > Player Settings에서 웹에 대한 Publishing Setings를 엽니다. 이렇게 하면 브라우저가 주요 데이터 파일을 IndexedDB 데이터베이스에 캐시할 수 있습니다.
기본 브라우저 HTTP 캐시를 사용한다고 해서 브라우저가 특정 리스폰스를 캐싱한다는 보장은 없습니다.이는 브라우저 HTTP 캐시의 공간이 제한되어 있어 브라우저가 너무 큰 파일을 캐싱할 수 없을 수도 있기 때문입니다.
로드 속드를 개선하기 위해 IndexedDB
를 사용하면 브라우저 제한을 초과하는 파일을 캐싱할 수 있습니다.더 많은 파일을 캐싱하면 다음 빌드를 실행할 때 다운로드한 콘텐츠를 사용자의 컴퓨터에서 사용할 수 있는 가능성이 높아집니다.
데이터 캐싱은 HTTP 리스폰스에 대해 IndexedDB 캐시에 있는 .data
파일만 캐싱합니다.에셋 번들을 캐싱하려면 데이터 캐싱을 활성화하고 unityInstance.Module.cacheControl()
을 오버라이드해야 합니다.
이렇게 하려면 Module.cacheControl(url)
이 요청한 에셋 번들 URL에 대해 must-revalidate
를 반환하는지 확인해야 합니다.예를 들어 createUnityInstance()
가 반환하는 Promise의 이행 콜백에서 unityInstance.Module.cacheControl()
함수를 오버라이드할 수 있습니다.
createUnityInstance()
에 대한 자세한 내용은 압축 빌드 및 서버 설정을 참조하십시오.
기본적으로 웹 캐시는 에셋 데이터 파일 .data
와 에셋 번들 파일 .bundle
을 저장하고 캐시에서 로드하기 전에 다시 확인합니다. 이 동작을 변경하려면 UnityLoader 설정을 변경하는 새 웹 템플릿을 추가합니다.
다음 예시는 커스텀 cacheControl 함수를 index.html
파일 내의 UnityLoader 설정에 추가하는 것을 보여줍니다.
var config = {
// ...
# if USE_DATA_CACHING
cacheControl: function (url) {
// Caching enabled for .data and .bundle files.
// Revalidate if file is up to date before loading from cache
if (url.match(/\.data/) || url.match(/\.bundle/)) {
return "must-revalidate";
}
// Caching enabled for .mp4 and .custom files
// Load file from cache without revalidation.
if (url.match(/\.mp4/) || url.match(/\.custom/)) {
return "immutable";
}
// Disable explicit caching for all other files.
// Note: the default browser cache may cache them anyway.
return "no-store";
},
# endif
// ...
}
cacheControl
함수는 요청한 URL을 파라미터로 받아 다음 중 하나를 반환합니다.
must-revalidate
- 함수가 must-revalidate를 반환하면 캐시가 활성화된 상태로 돌아가고 캐시에서 파일을 로드하기 전에 파일을 다시 확인합니다.
immutable
- 함수가 immutable을 반환하면 캐시가 활성화되고 파일을 다시 확인하지 않고 캐시에서 로드합니다.
no-store
- 함수가 no-store를 반환하면 캐시가 비활성화됩니다.
브라우저는 .html, .js, .css, .json, .jpg, .png 등 특정 파일 타입을 자동으로 저장(캐시)하므로 웹 캐시에 명시적으로 저장할 필요가 없습니다. 일반적으로 웹 캐시는 대용량 파일과 커스텀 파일 포맷을 사용하는 파일이 될 수 있습니다.
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.