Skip to content

Commit

Permalink
Merge pull request #537 from nhn/prepare
Browse files Browse the repository at this point in the history
UI 2.10.0 CacheStorage 1.4.0 LogViewer 2.1.0 업데이트
smflt-nhn authored Sep 25, 2024
2 parents fdc4e7c + d02d2ae commit ac52431
Showing 23 changed files with 1,175 additions and 161 deletions.
267 changes: 216 additions & 51 deletions docs/CacheStorage/README.en.md
Original file line number Diff line number Diff line change
@@ -151,6 +151,57 @@ public void Something()
}
```

### CacheRequestConfiguration
This setting allows for fine control over cache requests.
* requestType : Determines when cached data should be revalidated with the server.
* ALWAYS : Revalidates every time a request is made.
* FIRSTPLAY : Revalidates every time the app is restarted and also when the validity period expires.
* ONCE : Revalidates when the validity period expires.
* LOCAL : Uses the cached data.
* reRequestTime : The local revalidation interval (in seconds).
* This is applied when requestType is FIRSTPLAY or ONCE.
* Revalidation occurs after the reRequestTime has elapsed since the last cache check.
* If the server’s set validity period is shorter, revalidation occurs based on that time.
* If set to 0, reRequestTime is ignored.
* validCacheTime : Local cache validity period (in seconds)
* min : Minimum time for cache reuse (in seconds)
* The cache is reused without revalidation until the specified time has passed.
* If set to 0, min is ignored.
* max : Maximum time for cache reuse (in seconds).
* New cache will be fetched once the specified time has elapsed.
* If set to 0, max is ignored.
* header
* Sets additional headers to be included with the server request.

```cs
using Gpm.CacheStorage;

public void Something()
{
string url;

CacheRequestType requestType = CacheRequestType.ONCE;

double reRequestTime = 60 * 60 * 2;

double cacheValidTimeMin = 60 * 5;
double cacheValidTimeMax = 60 * 60 * 24 * 30;
CacheValidTime validCacheTime = new CacheValidTime(cacheValidTimeMin, cacheValidTimeMax));

Dictionary<string, string> header = new Dictionary<string, string>();
header.Add("Content-Type", "application/json");

CacheRequestConfiguration config = new CacheRequestConfiguration(requestType, reRequestTime, validCacheTime, header);
GpmCacheStorage.Request(url, config, (GpmCacheResult result) =>
{
if (result.IsSuccess() == true)
{
bytes[] data = result.Data;
}
});
}
```

### GpmCacheResult
Result value of cached data. Returns cache information and data.
* IsSuccess allows you to obtain success or not.
@@ -256,12 +307,41 @@ public IEnumerator Something()
Can request a texture cache using GpmCacheStorage.RequestTexture.
* If the texture is loaded after running the app, reuse them will be reused.
* Load and use cached textures when cached data and web data are the same data.
* preload : Immediately loads cached textures from the local storage
* If there is a discrepancy between cached data and web data, the callback will be invoked once more.

#### RequestTexture

```cs
public void Something()
{
string url;
GpmCacheStorage.RequestTexture(url, (cachedTexture) =>
bool preload = true;

GpmCacheStorage.RequestTexture(url, preload, (CachedTexture cachedTexture) =>
{
if (cachedTexture != null)
{
Texture texture = cachedTexture.texture;
}
});
}
```

#### Add Configuration

```cs
public void Something()
{
string url;

Dictionary<string, string> header = new Dictionary<string, string>();
header.Add("Authorization ", "value");
CacheRequestConfiguration config = new CacheRequestConfiguration(header);

bool preload = true;

GpmCacheStorage.RequestTexture(url, config, preload, (CachedTexture cachedTexture) =>
{
if (cachedTexture != null)
{
@@ -271,12 +351,16 @@ public void Something()
}
```

#### Use Coroutine

```cs
public IEnumerator Something()
{
CachedTexture cachedTexture;
string url;
yield return GpmCacheStorage.RequestTexture(url, (CachedTexture recvCachedTexture) =>
bool preload = true;

CachedTexture cachedTexture;
yield return GpmCacheStorage.RequestTexture(url, preload, (CachedTexture recvCachedTexture) =>
{
cachedTexture = recvCachedTexture;
});
@@ -331,78 +415,134 @@ public void Something()
```

## More effective web cache
Web cache is about twice as fast as normal requests.
Importing locally is faster, but cannot determine if it is up to date.
Using web caching avoids downloading content if it is identical, making the process about twice as fast compared to standard web requests.

Directly fetching from local cache is even faster as it bypasses web requests, but it cannot verify whether the content is up to date.

![](Images/3_en.png)

Can use the web cache more effectively by validating it only when you need it.

### Web Cache Validation Strategy

If security is critical or requires continuous renewal, use normal network communications to ensure integrity.
In addition, different verification strategies depending on whether content is more important for performance or integrity can further improve performance.

![](Images/4_en.png)

Cache Storage supports 4 validation strategies

### CacheRequestType
Can decide when to re-validate cached data to the server.
More revalidation ensures integrity, and more reuse improves performance.
CacheStorage supports the following four validation request types:

* ALWAYS
* Revalidate that data has changed on the server at every request.
* Same as GpmCacheStorage.RequestHttpCache.
* Revalidates content with each request.
* FIRSTPLAY
* Re-validated every time the app is re-launched, and also re-verified when the validity period is over.
* Revalidates based on expiration or RequestTime settings.
* Revalidates content the first time it is requested after the app starts.
Revalidates content when it is requested again after restarting the app.
Revalidates content based on its validity period after these checks.
* ONCE
* Will be re-verified at the end of the validity period.
* Revalidates based on expiration or RequestTime settings.
* Revalidates content if the validity period has expired when the content is requested.
* LOCAL
* Uses cached data.
* Same as GpmCacheStorage.RequestLocalCache.
* Uses the cached content from local storage.

#### Can request and able to request
* If no argument is used, the default value set in Initialize is used.
ALWAYS: Ensures that content is revalidated with each request, so no content is downloaded if it remains the same.

```cs
using Gpm.CacheStorage;
FIRSTPLAY and ONCE: Use cached content from local storage until the specified validity period expires, providing faster access.

public void Something()
{
// Revalidate every time requested
string url;
CacheRequestType requestType = CacheRequestType.ALWAYS;
GpmCacheStorage.Request(url, requestType, (GpmCacheResult result) =>
{
if (result.IsSuccess() == true)
{
bytes[] data = result.Data;
}
});
}
```
### Cache Validation and Performance

More frequent revalidation ensures content integrity, while higher reuse improves performance.

For scenarios where security is crucial or continuous updates are necessary, traditional network communication is used to ensure integrity.

![](Images/4_en.png)

### Web Cache Validity Period

Web cache validation operates based on the validity period set by the server for each piece of content.
If a CDN sets a validity period for content, you can configure the revalidation frequency.

* Web Cache Validity Period
* If the web cache validity period is set to 0, it will always perform revalidation similar to the ALWAYS setting.
* If the validity period is set to 3 hours, revalidation will be performed after 3 hours for FIRSTPLAY and ONCE requests.

### ReRequestTime
FIRSTPLAY, ONCE will reuse the cache until it expires based on the data received.
However, you can set the frequency of revalidation requests within the cluster.
* After a set number of seconds, the server will be re-validated upon callback.
* Do not re-request when set to 0.
### Controlling Web Cache Timing

#### Can request and a factor when request
* If the argument is 0 or not used, the default value set in Initialize is used.
Many contents may be difficult to control from the server side.

CacheStorage allows clients to manage these settings.

* reRequestTime
* Allows setting a time for requesting revalidation.
* Revalidation will occur after the specified reRequestTime has elapsed.
* For example, if reRequestTime is set to 1 day, revalidation will occur after 1 day.
* If the server's set validity period is shorter, revalidation will occur based on that time.
* For example, if the content's validity period is 1 day and reRequestTime is set to 3 days, revalidation will occur after 1 day.
* If reRequestTime is set to 0, only the validity period will be checked.
* validCacheTime
* Allows setting the minimum and maximum validity period for local cache.
* min: Minimum time for cache reuse
* The cache will be reused without revalidation before the specified time.
* If set to 0, min is ignored.
* max : Maximum time for cache reuse
* New cache will be fetched after the specified time has elapsed.
* If set to 0, max is ignored.

### Utilizing Web Cache
By combining cache validation strategies with cache time control, you can use web cache more effectively.

* If the validation strategy is ALWAYS and validCacheTime has a min of 5 minutes and a max of 30 days:
* The ALWAYS strategy provides high integrity but can be optimized for performance using the min setting of validCacheTime.
* For instance, you can use the local cache for 5 minutes and perform revalidation after 5 minutes.
* Utilize the max setting of validCacheTime to enhance integrity.
* Even if the cache has not changed, new content will be downloaded after 30 days.

* If the validation strategy is FIRSTPLAY and validCacheTime has a min of 5 minutes and reRequestTime is 10 minutes:
* The min setting of validCacheTime helps improve performance
* The FIRSTPLAY strategy performs validation on the first request after the app starts, but local cache will be used for up to 5 minutes.
* Use reRequestTime to control the maximum validity period.
* Revalidation will occur after 5 minutes on the first request, but if the validity period is longer than 10 minutes, revalidation will occur after 10 minutes.
* if the validity period is shorter than reRequestTime, revalidation will occur after the validity period,
* but revalidation will be performed after the 5-minute min period set by validCacheTime.

### CacheRequestConfiguration

This configuration allows for fine control over cache requests.
If no arguments are provided, the default values set in Initialize will be used.

* requestType : Determines when the cached data should be revalidated with the server.
* ALWAYS : Revalidates with the server on every request.
* FIRSTPLAY : Revalidates every time the app is restarted, as well as when the validity period expires.
* ONCE : Revalidates only when the validity period expires.
* LOCAL : Uses the cached data without revalidation.
* reRequestTime : The local revalidation interval (in seconds).
* Applies when requestType is FIRSTPLAY or ONCE.
* Revalidation will occur after the reRequestTime has elapsed following cache validation.
* If the server's validity period is shorter, revalidation will occur according to the server's validity period.
* Ignored if set to 0.
* validCacheTime : The local cache validity period (in seconds).
* min : Minimum time for cache reuse (in seconds).
* The cache will be reused without revalidation until the specified time has elapsed.
* Ignored if set to 0.
* max : Maximum time for cache reuse (in seconds).
* A new cache will be fetched after the specified time has elapsed.
* Ignored if set to 0.
* header
* Configures additional headers to be sent with the server request.

```cs
using Gpm.CacheStorage;

public void Something()
{
// Cache that has been requested for 5 minutes is revalidated to the server
string url;
double fiveMinutes = 5 * 60;
GpmCacheStorage.Request(url, fiveMinutes, (GpmCacheResult result) =>

CacheRequestType requestType = CacheRequestType.ONCE;

double reRequestTime = 60 * 60 * 2;

double cacheValidTimeMin = 60 * 5;
double cacheValidTimeMax = 60 * 60 * 24 * 30;
CacheValidTime validCacheTime = new CacheValidTime(cacheValidTimeMin, cacheValidTimeMax));

Dictionary<string, string> header = new Dictionary<string, string>();
header.Add("Content-Type", "application/json");

CacheRequestConfiguration config = new CacheRequestConfiguration(requestType, reRequestTime, validCacheTime, header);
GpmCacheStorage.Request(url, config, (GpmCacheResult result) =>
{
if (result.IsSuccess() == true)
{
@@ -412,6 +552,31 @@ public void Something()
}
```

Here is the analysis based on the provided sample configuration:
* Values
* requestType : ONCE
* reRequestTime : 2 hours (60 * 60 * 2)
* cacheValidTimeMin : 5 minutes (60 * 5)
* cacheValidTimeMax : 30 days (60 * 60 * 24 * 30)
* 해석
* requestType가 ONCE
* Revalidation will occur only when the validity period has expired.
* cacheValidTimeMin: 5 minutes
* Revalidation will not be performed before 5 minutes have elapsed.
* reRequestTime: 2 hours
* Revalidation will be performed if a request is made after 2 hours.
* If the validity period is shorter than 2 hours, revalidation will occur after that shorter period.
* cacheValidTimeMax: 30 days
* If no revalidation has occurred within 30 days, a new cache will be fetched.
* Time counting for revalidation starts from the moment of the last revalidation.
* Performance
* Before cacheValidTimeMin, reRequestTime, and expiration:
* Data is read from the local cache, which is fast.
* After reRequestTime and expiration:
* Even if a request is made to the server, if the content has not changed, no new download occurs, improving performance.
* After cacheValidTimeMax has elapsed:
* A new cache will be fetched, resulting in a download, which is similar to regular server communication.

### Viewer
Can view cache information for Cache Storage.

311 changes: 238 additions & 73 deletions docs/CacheStorage/README.md

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions docs/CacheStorage/ReleaseNotes.en.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,25 @@

🌏 [한국어](ReleaseNotes.md)

## 1.4.0

### Date

* 2024.09.25

### Added
* Improved control over cache requests
* Request(string url, CacheRequestConfiguration config, Action<GpmCacheResult> onResult)
* CacheRequestConfiguration
* Added header configuration feature
* Added local cache validity period configuration feature (CacheValidTime)
* min : Minimum time for cache reuse (seconds)
* The cache will be reused without checking for changes until the specified time.
* Ignored if set to 0.
* max : Maximum time for cache reuse (seconds)
* New cache will be fetched after the specified time has elapsed.
* Ignored if set to 0.

## 1.3.1

### Date
19 changes: 19 additions & 0 deletions docs/CacheStorage/ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,25 @@

🌏 [English](ReleaseNotes.en.md)

## 1.4.0

### Date

* 2024.09.25

### Added
* 더 세밀하게 캐시 요청을 제어할 수 있도록 개선
* Request(string url, CacheRequestConfiguration config, Action<GpmCacheResult> onResult)
* CacheRequestConfiguration
* 헤더 설정 기능 추가
* 로컬 캐시 유효 기간 설정 기능 추가(CacheValidTime)
* min : 캐시 재사용의 최소 시간 (초)
* 설정한 시간 까지 캐시 변경 여부 검증 없이 재사용 합니다.
* 0일 경우 무시됩니다.
* max : 캐시 재사용의 최대 시간 (초)
* 설정한 시간이 지나면 새로운 캐시를 받습니다.
* 0일 경우 무시됩니다.

## 1.3.1

### Date
15 changes: 11 additions & 4 deletions docs/LogViewer/README.en.md
Original file line number Diff line number Diff line change
@@ -53,6 +53,8 @@
* Configure whether to display the name of the scene in playing when there is a log.
* Send Mail
* Send all logs to specified email address.
* Save Log File
* Save the entire log to a local file.
* Clear
* Delete all logs.

@@ -103,6 +105,8 @@
![inspector](./images/inspector.png)
* Set Gesture Enable
* Enable or disable LogView gesture.
* Set Opener Enable
* Enable or disable the UI that activates Log View.
* Mail Setting
* To: The Recipient's email address
* User Name: Sender's email address
@@ -169,10 +173,13 @@

* Enabling Each Platform
* All Platforms
* Enable using the Back Quote Key.</br>
![backquote](./images/backquote.png)
* Use gesture to enable iOS/Android platforms.
* Touch the screen for a second with five fingers.
* Use the Back Quote Key to enable. (Gesture Enable)
* ![backquote](./images/backquote.png)
* Click the Log button to activate it. (Opener Enable)
* ![img.png](./images/logbtn.png)
* iOS/Android
* Use a gesture to enable iOS/Android platforms. (Opener Enable)
* Touch the screen with five fingers for one second.

* The following types of logs automatically trigger the LogViewer.
* LogType.Error
15 changes: 11 additions & 4 deletions docs/LogViewer/README.md
Original file line number Diff line number Diff line change
@@ -53,6 +53,8 @@
* 로그가 발생했을 때 재생 중인 Scene 이름을 보여줄지 설정합니다.
* Send Mail
* 전체 로그를 설정한 이메일로 전송합니다.
* Save LogFile
* 전체 로그를 로컬 파일로 저장합니다.
* Clear
* 전체 로그를 삭제합니다.

@@ -103,6 +105,8 @@
![inspector](./images/inspector.png)
* Gesture Enable 설정
* LogView를 활성화하는 제스처를 켜거나 끌 수 있습니다.
* Opener Enable 설정
* LogView를 활성화하는 UI를 켜거나 끌 수 있습니다.
* 이메일 설정
* To: 받는 사람 이메일 주소
* User Name: 보내는 사람 이메일 주소
@@ -167,10 +171,13 @@

* 플랫폼별 활성화 방법
* 플랫폼 공통
* BackQuote Key로 활성화합니다.</br>
![backquote](./images/backquote.png)
* iOS/Android 플랫폼은 제스처로 활성화합니다.
* 손가락 다섯개로 1초간 화면을 터치합니다.
* BackQuote Key로 활성화합니다. (Gesture Enable)
* ![backquote](./images/backquote.png)
* Log 버튼을 클릭하여 활성화합니다. (Opener Enable)
* ![img.png](./images/logbtn.png)
* iOS/Android
* 제스처를 사용하여 활성화합니다. (Opener Enable)
* 손가락 다섯 개로 1초간 화면을 터치합니다.

* 다음 타입의 로그가 발생하면 자동으로 활성화됩니다.
* LogType.Error
10 changes: 10 additions & 0 deletions docs/LogViewer/ReleaseNotes.en.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,16 @@

🌏 [한국어](ReleaseNotes.md)

## 2.1.0

### Date

* 2024.09.25

### Added
* Added LogViewer Open UI Feature
* Added Log File Saving Feature

## 2.0.4

### Date
10 changes: 10 additions & 0 deletions docs/LogViewer/ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,16 @@

🌏 [English](ReleaseNotes.en.md)

## 2.1.0

### Date

* 2024.09.25

### Added
* LogViewer 오픈 UI 기능 추가
* 로그를 로컬 파일로 저장하는 기능 추가

## 2.0.4

### Date
Binary file modified docs/LogViewer/images/console.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/LogViewer/images/inspector.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/LogViewer/images/logbtn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 14 additions & 1 deletion docs/UI/ReleaseNotes.en.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
# Release notes
# Release notes

🌏 [한국어](ReleaseNotes.md)

## 2.10.0

### Date

* 2024.09.25

### Added
* WebCacheImage
* Function to add headers
* Function to select cache request types
* Function to change cache re-request time
* Function to set minimum and maximum validity for cache

## 2.9.0

### Date
18 changes: 17 additions & 1 deletion docs/UI/ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
# Release notes
# Release notes

🌏 [English](ReleaseNotes.en.md)

## 2.10.0

### Date

* 2024.09.25

### Added
* WebCacheImage
* 헤더 추가할 수 있는 기능
* 캐시 요청 타입 선택할 수 있는 기능
* 캐시 재요청 시간 변경할 수 있는 기능
* 캐시 유효 최소 및 최대 설정할 수 있는 기능

### Updated
* CacheStorage 1.4.0 업데이트

## 2.9.0

### Date
289 changes: 283 additions & 6 deletions docs/UI/WebCacheImage/README.en.md
Original file line number Diff line number Diff line change
@@ -14,33 +14,78 @@ This component displays images by caching web images using URLs.

## How to use
Add a **WebCacheImage** component to your UI object.

* If RawImage does not exist, a RawImage component is also created.
* If there is a RawImage, it is linked to the RawImage component.

![WebCacheImage.png](https://github.com/nhn/gpm.unity/blob/main/docs/UI/WebCacheImage/images/WebCacheImage.png?raw=true)
![WebCacheImage.png](./images/WebCacheImage.png)

1. Url: The URL to load the image.
2. Pre Load: A delay occurs when obtaining an image through a web request. If a cache is available, it will preload the image.
3. Cache Config: Detailed cache settings
* Request Type: Set the cache request type
* Re Request Time: Set the maximum revalidation period for the cache (in seconds)
* Valid Cache Time
* min: Minimum cache validity period (in seconds)
* max: Maximum cache validity period (in seconds)
4. On Load Texture: The event that occurs when the texture is loaded through a request.

### Cache Details

WebCacheImage uses CacheStorage for image cache management.
* It can be controlled through Cache Config.
* Reference : [Using Web Cache More Effectively](https://github.com/nhn/gpm.unity/tree/main/docs/CacheStorage#%EB%8D%94-%ED%9A%A8%EA%B3%BC%EC%A0%81%EC%9D%B8-%EC%9B%B9-%EC%BA%90%EC%8B%9C-%EC%82%AC%EC%9A%A9)

### Request Header Settings

Can set the headers through the arguments.

1. This is the URL to load the image.
2. There is a delay when getting images via web request. If there is a cache, it is loaded in advance.
3. This event is when the Texture is loaded through a request.
```cs
WebCacheImage cache;

Dictionary<string, string> header = new Dictionary<string, string>();
header.Add("key", "value");

cache.SetHeader(header);
```

## API

### SetUrl

Set the URL to load the image.

```cs
void SetUrl(string url)
void SetUrl(string url, Dictionary<string, string> header)
```

**Example**
```cs
WebCacheImage cache;

cache.SetUrl(cacheData.url);
string url = "url";

cache.SetUrl(url);
```

```cs
WebCacheImage cache;

string url = "url";
Dictionary<string, string> header = new Dictionary<string, string>();
header.Add("key", "value");

cache.SetUrl(url, header);
```

### SetLoadTextureEvent

Set an event when loading an image.

```cs
void SetLoadTextureEvent(UnityAction<Texture> onListener)
```

**Example**
```cs
WebCacheImage cache;
@@ -49,4 +94,236 @@ cache.SetLoadTextureEvent(OnLoadTexture);
public void OnLoadTexture(Texture texture)
{
}
```

### AddLoadTextureEvent

Adds an event when loading an image.

```cs
void AddLoadTextureEvent(UnityAction<Texture> onListener)
```

**Example**
```cs
WebCacheImage cache;
cache.AddLoadTextureEvent(OnLoadTexture);

public void OnLoadTexture(Texture texture)
{
}
```

### CleatLoadTextureEvent

Initializes the event when loading an image.
```cs
void CleatLoadTextureEvent()
```

**Example**
```cs
WebCacheImage cache;
cache.CleatLoadTextureEvent();
```

### SetPreloadSetting

Sets whether to preload the image when requesting it.

```cs
void void SetPreloadSetting(bool preLoad)
```

**Example**
```cs
WebCacheImage cache;

cache.SetPreloadSetting(true);
```

### SetHeader

Sets the headers used when requesting an image.

```cs
void SetHeader(Dictionary<string, string> header)
```

**Example**
```cs
WebCacheImage cache;

Dictionary<string, string> header = new Dictionary<string, string>();
header.Add("key", "value");

cache.SetHeader(header);
```

### SetCacheConfig

Sets the detailed cache configuration when requesting an image.

```cs
void SetCacheConfig(CacheRequestConfiguration config)
```

**Example**
```cs
WebCacheImage cache;

CacheRequestConfiguration cacheConfig = new CacheRequestConfiguration(
CacheRequestType.ONCE,
60 * 60 * 2,
new CacheValidTime(60 * 5, 60 * 60 * 24 * 30));

cache.SetCacheConfig(cacheConfig);
```

### SetCacheRequestType

Sets how to revalidate the cache when requesting an image.

```cs
void SetCacheRequestType(CacheRequestType requestType)
```

**Example**
```cs
WebCacheImage cache;

CacheRequestType requestType = CacheRequestType.FIRSTPLAY;

cache.SetCacheRequestType(requestType);
```

### SetCacheReRequestTime

Sets the time for revalidating the cache when requesting an image.

```cs
void SetCacheReRequestTime(double reRequestTime)
```

* After the specified time (in seconds), the server will revalidate whether the image has changed.
* If the value is 0, it follows the expiration time set by the content server.
* Revalidation will occur sooner compared to the content expiration set on the server.

**Example**
```cs
WebCacheImage cache;

double reRequestTime = 60 * 60 * 2; // 2 Hours
cache.SetCacheReRequestTime(reRequestTime);
```

### SetCacheValidMinTime

Sets the minimum reuse period for the image cache.

```
public void SetCacheValidMinTime(double min)
```

* Setting a minimum time (in seconds) means the cached version will be used until that time.
* If the value is 0, it will be ignored.

**Example**
```cs
WebCacheImage cache;

double validCacheMinTime = 60 * 5; // 5 Minutes
cache.SetCacheValidMinTime(validCacheMinTime);
```

### SetCacheValidMaxTime

Sets the maximum reuse period for the image cache.

```cs
public void SetCacheValidMaxTime(double max)
```

* Setting a maximum time (in seconds) means a new cache will be downloaded after that time.
* If the value is 0, it will be ignored.

**Example**
```cs
WebCacheImage cache;

double validCacheMaxTime = 60 * 60 * 24 * 30; // 30 Days
cache.SetCacheValidMaxTime(validCacheMaxTime);
```

### SetCacheValidTime

Sets the minimum and maximum reuse periods for the image cache.

```cs
void SetCacheValidTime(double min, double max)
```

* Setting a minimum time (in seconds) means the cached version will be used until that time.
* Setting a maximum time (in seconds) means a new cache will be downloaded after that time.
* If the value is 0, it will be ignored.

**Example**
```cs
WebCacheImage cache;

double validCacheMinTime = 60 * 5; // 5 Minutes
double validCacheMaxTime = 60 * 60 * 24 * 30; // 30 Days
cache.SetCacheValidTime(validCacheMinTime, validCacheMaxTime);
```

### GetURL

Gets the URL for the image to be loaded.

```cs
string GetURL()
```

### GetPreloadSetting

Gets whether to preload the image when requesting it.

```cs
bool GetPreloadSetting()
```

### GetCacheRequestType

Gets the time for revalidating the cache when requesting an image.

```cs
CacheRequestType GetCacheRequestType()
```

### GetCacheReRequestTime

Gets the minimum reuse period for the image cache.

```cs
double GetCacheReRequestTime()
```

### GetCacheValidMinTime

Gets the maximum reuse period for the image cache.

```cs
double GetCacheValidMinTime()
```

### GetCacheValidMaxTime

이미지 캐시의 최대 재사용 기간을 얻습니다.

```cs
double GetCacheValidMaxTime()
```
291 changes: 285 additions & 6 deletions docs/UI/WebCacheImage/README.md
Original file line number Diff line number Diff line change
@@ -13,33 +13,79 @@
URL을 이용하여 웹 이미지를 캐시 하여 이미지를 보여주는 컴포넌트입니다.

## 사용 방법
UI 오브젝트에 **WebCacheImage** 컴포넌트를 추가합니다.
UI 오브젝트에 **WebCacheImage** 컴포넌트를 추가합니다.
* RawImage가 없다면 RawImage 컴포넌트도 같이 생성됩니다.
* RawImage가 있다면 RawImage 컴포넌트에 연동됩니다.

![WebCacheImage.png](https://github.com/nhn/gpm.unity/blob/main/docs/UI/WebCacheImage/images/WebCacheImage.png?raw=true)
![WebCacheImage.png](./images/WebCacheImage.png)

1. 이미지를 불러올 URL입니다.
2. 웹 요청을 통해 이미지를 얻을 경우 딜레이가 있습니다. 캐시가 있을 경우 미리 불러옵니다.
3. Texture가 요청을 통해 Load 되었을 때의 이벤트입니다.
1. Url: 이미지를 불러올 URL입니다.
2. Pre Load: 웹 요청을 통해 이미지를 얻을 경우 딜레이가 발생합니다. 캐시가 있을 경우 미리 불러옵니다.
3. Cache Config: 캐시 세부 설정
* Request Type: 캐시 요청 타입 설정
* Re Request Time: 캐시 최대 재검증 기간(초) 설정
* Valid Cache Time
* min: 최소 캐시 유효 기간(초)
* max: 최대 캐시 유효 기간(초)
4. On Load Texture: Texture가 요청을 통해 로드되었을 때의 이벤트입니다.

### 캐시 세부 설정

WebCacheImage는 이미지 캐시 관리를 위해 CacheStorage를 사용합니다.
* Cache Config를 통해 제어할 수 있습니다.
* 참조 : [더 효과적인 웹 캐시 사용](https://github.com/nhn/gpm.unity/tree/main/docs/CacheStorage#%EB%8D%94-%ED%9A%A8%EA%B3%BC%EC%A0%81%EC%9D%B8-%EC%9B%B9-%EC%BA%90%EC%8B%9C-%EC%82%AC%EC%9A%A9)

### 요청 헤더 설정

인자를 통해 헤더를 설정할 수 있습니다.

```cs
WebCacheImage cache;

Dictionary<string, string> header = new Dictionary<string, string>();
header.Add("key", "value");

cache.SetHeader(header);
```

## API

### SetUrl

이미지를 불러올 URL을 설정합니다.

```cs
void SetUrl(string url)
void SetUrl(string url, Dictionary<string, string> header)
```

**Example**
```cs
WebCacheImage cache;

cache.SetUrl(cacheData.url);
string url = "url";

cache.SetUrl(url);
```

```cs
WebCacheImage cache;

string url = "url";
Dictionary<string, string> header = new Dictionary<string, string>();
header.Add("key", "value");

cache.SetUrl(url, header);
```

### SetLoadTextureEvent

이미지를 로드할 때 이벤트를 설정합니다.

```cs
void SetLoadTextureEvent(UnityAction<Texture> onListener)
```

**Example**
```cs
WebCacheImage cache;
@@ -48,4 +94,237 @@ cache.SetLoadTextureEvent(OnLoadTexture);
public void OnLoadTexture(Texture texture)
{
}
```

### AddLoadTextureEvent

이미지를 로드할 때 이벤트를 추가합니다.

```cs
void AddLoadTextureEvent(UnityAction<Texture> onListener)
```

**Example**
```cs
WebCacheImage cache;
cache.AddLoadTextureEvent(OnLoadTexture);

public void OnLoadTexture(Texture texture)
{
}
```

### CleatLoadTextureEvent

이미지를 로드할 때 이벤트를 초기화합니다.

```cs
void CleatLoadTextureEvent()
```

**Example**
```cs
WebCacheImage cache;
cache.CleatLoadTextureEvent();
```

### SetPreloadSetting

이미지를 요청할 때 미리 불러오는지 여부를 설정합니다.

```cs
void void SetPreloadSetting(bool preLoad)
```

**Example**
```cs
WebCacheImage cache;

cache.SetPreloadSetting(true);
```

### SetHeader

이미지를 요청할 때 사용하는 헤더를 설정합니다.

```cs
void SetHeader(Dictionary<string, string> header)
```

**Example**
```cs
WebCacheImage cache;

Dictionary<string, string> header = new Dictionary<string, string>();
header.Add("key", "value");

cache.SetHeader(header);
```

### SetCacheConfig

이미지를 요청할 때 캐시 세부 설정을 합니다.

```cs
void SetCacheConfig(CacheRequestConfiguration config)
```

**Example**
```cs
WebCacheImage cache;

CacheRequestConfiguration cacheConfig = new CacheRequestConfiguration(
CacheRequestType.ONCE,
60 * 60 * 2,
new CacheValidTime(60 * 5, 60 * 60 * 24 * 30));

cache.SetCacheConfig(cacheConfig);
```

### SetCacheRequestType

이미지를 요청할 때 캐시를 재검증하는 방법을 설정합니다.

```cs
void SetCacheRequestType(CacheRequestType requestType)
```

**Example**
```cs
WebCacheImage cache;

CacheRequestType requestType = CacheRequestType.FIRSTPLAY;

cache.SetCacheRequestType(requestType);
```

### SetCacheReRequestTime

이미지를 요청할 때 캐시를 재검증하는 시간을 설정합니다.

```cs
void SetCacheReRequestTime(double reRequestTime)
```

* 설정한 시간(초) 이후 이미지가 바뀌었는지 서버에 재검증합니다.
* 값이 0이라면 콘텐츠 서버에 설정된 유효기간에 따릅니다.
* 서버에 콘텐츠 유효기간과 비교해 더 빠른 시간에 재검증합니다.

**Example**
```cs
WebCacheImage cache;

double reRequestTime = 60 * 60 * 2; // 2 Hours
cache.SetCacheReRequestTime(reRequestTime);
```

### SetCacheValidMinTime

이미지 캐시의 최소 재사용 기간을 설정합니다.

```
public void SetCacheValidMinTime(double min)
```

* 최소 시간(초)을 설정하면 해당 시간까지 무조건 저장된 캐시를 읽습니다.
* 값이 0이라면 무시됩니다.

**Example**
```cs
WebCacheImage cache;

double validCacheMinTime = 60 * 5; // 5 Minutes
cache.SetCacheValidMinTime(validCacheMinTime);
```

### SetCacheValidMaxTime

이미지 캐시의 최대 재사용 기간을 설정합니다.

```cs
public void SetCacheValidMaxTime(double max)
```

* 최대 시간(초)을 설정하면 해당 시간 이후 무조건 새로운 캐시를 다운로드합니다.
* 값이 0이라면 무시됩니다.

**Example**
```cs
WebCacheImage cache;

double validCacheMaxTime = 60 * 60 * 24 * 30; // 30 Days
cache.SetCacheValidMaxTime(validCacheMaxTime);
```

### SetCacheValidTime

이미지 캐시의 최대 및 최소 재사용 기간을 설정합니다.

```cs
void SetCacheValidTime(double min, double max)
```

* 최소 시간(초)을 설정하면 해당 시간까지 무조건 저장된 캐시를 읽습니다.
* 최대 시간(초)을 설정하면 해당 시간 이후 무조건 새로운 캐시를 다운로드합니다.
* 값이 0이라면 무시됩니다.

**Example**
```cs
WebCacheImage cache;

double validCacheMinTime = 60 * 5; // 5 Minutes
double validCacheMaxTime = 60 * 60 * 24 * 30; // 30 Days
cache.SetCacheValidTime(validCacheMinTime, validCacheMaxTime);
```

### GetURL

이미지를 불러올 URL을 얻습니다.

```cs
string GetURL()
```

### GetPreloadSetting

이미지를 요청할 때 미리 불러오는지 여부를 얻습니다.

```cs
bool GetPreloadSetting()
```

### GetCacheRequestType

이미지를 요청할 때 캐시를 재검증하는 방법을 얻습니다.

```cs
CacheRequestType GetCacheRequestType()
```

### GetCacheReRequestTime

이미지를 요청할 때 캐시를 재검증하는 시간을 얻습니다.

```cs
double GetCacheReRequestTime()
```

### GetCacheValidMinTime

이미지 캐시의 최소 재사용 기간을 얻습니다.

```cs
double GetCacheValidMinTime()
```

### GetCacheValidMaxTime

이미지 캐시의 최대 재사용 기간을 얻습니다.

```cs
double GetCacheValidMaxTime()
```
Binary file modified docs/UI/WebCacheImage/images/WebCacheImage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
15 changes: 12 additions & 3 deletions release/CacheStorage/service.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
<?xml version="1.0" encoding="UTF-8" ?>
<info version="13">
<info version="14">
<title>CacheStorage</title>
<status>publish</status>
<description>$DESCRIPTION</description>
<version>1.3.1</version>
<version>1.4.0</version>
<dependencies>
<unity>
<version>2019.4.0+</version>
</unity>
<Common>
<version>2.3.1</version>
<version>2.4.0</version>
<install>auto</install>
</Common>
</dependencies>
<packageList>
<package>
<version>1.4.0</version>
<installList>
<install>
<name>gpm_cachestorage_v1.4.0.unitypackage</name>
<path>GPM/CacheStorage</path>
</install>
</installList>
</package>
<package>
<version>1.3.1</version>
<installList>
Binary file not shown.
19 changes: 14 additions & 5 deletions release/LogViewer/service.xml
Original file line number Diff line number Diff line change
@@ -1,27 +1,36 @@
<?xml version="1.0" encoding="UTF-8" ?>
<info version="11">
<info version="12">
<title>LogViewer</title>
<status>publish</status>
<description>$DESCRIPTION</description>
<version>2.0.4</version>
<version>2.1.0</version>
<dependencies>
<unity>
<version>2019.4.0+</version>
</unity>
<Common>
<version>2.3.3</version>
<version>2.4.0</version>
<install>auto</install>
</Common>
<UI>
<version>2.9.0</version>
<version>2.10.0</version>
<install>auto</install>
</UI>
<CacheStorage>
<version>1.3.1</version>
<version>1.4.0</version>
<install>auto</install>
</CacheStorage>
</dependencies>
<packageList>
<package>
<version>2.1.0</version>
<installList>
<install>
<name>gpm_logviewer_v2.1.0.unitypackage</name>
<path>GPM/LogViewer</path>
</install>
</installList>
</package>
<package>
<version>2.0.4</version>
<installList>
Binary file added release/UI/gpm_ui_v2.10.0.unitypackage
Binary file not shown.
17 changes: 13 additions & 4 deletions release/UI/service.xml
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
<?xml version="1.0" encoding="UTF-8" ?>
<info version="27">
<info version="28">
<title>UI</title>
<status>publish</status>
<description>$DESCRIPTION</description>
<version>2.9.0</version>
<version>2.10.0</version>
<dependencies>
<unity>
<version>2019.4.0+</version>
</unity>
<Common>
<version>2.3.3</version>
<version>2.4.0</version>
</Common>
<CacheStorage>
<version>1.3.1</version>
<version>1.4.0</version>
</CacheStorage>
</dependencies>
<packageList>
<package>
<version>2.10.0</version>
<installList>
<install>
<name>gpm_ui_v2.10.0.unitypackage</name>
<path>GPM/UI</path>
</install>
</installList>
</package>
<package>
<version>2.9.0</version>
<installList>
6 changes: 3 additions & 3 deletions release/servicelist.xml
Original file line number Diff line number Diff line change
@@ -14,15 +14,15 @@
</service>
<service>
<name>UI</name>
<version>2.9.0</version>
<version>2.10.0</version>
</service>
<service>
<name>Shader</name>
<version>0.1.0</version>
</service>
<service>
<name>LogViewer</name>
<version>2.0.4</version>
<version>2.1.0</version>
</service>
<service>
<name>Communicator</name>
@@ -42,6 +42,6 @@
</service>
<service>
<name>CacheStorage</name>
<version>1.3.1</version>
<version>1.4.0</version>
</service>
</serviceList>

0 comments on commit ac52431

Please sign in to comment.