#C286. URL Content Caching with Expiry

    ID: 46222 Type: Default 1000ms 256MiB

URL Content Caching with Expiry

URL Content Caching with Expiry

You are required to implement a caching mechanism for fetching URL content. In this problem, a request is characterized by a timestamp, a URL, and a cache duration (in seconds). The caching mechanism should work as follows:

  • If the URL has been fetched before and the time elapsed since the last fetch is strictly less than the provided cache duration, return the cached content.
  • If the URL is not in the cache or the cached entry has expired, "fetch" the new content, update the cache, and return it.

For simulation purposes, when "fetching" a URL, if the URL is exactly http://example.com then the fetched content is Example Domain; for any other URL, the fetch will fail and you must return None.

Note: The input will be given in chronological order (non-decreasing timestamps).

inputFormat

The first line of input contains an integer Q representing the number of queries. Each of the following Q lines contains a query with three space-separated items:

  • An integer T representing the current time in seconds.
  • A string URL.
  • An integer D representing the cache duration in seconds.

It is guaranteed that the timestamps (T) are given in non-decreasing order.

outputFormat

For each query, output the fetched content on a separate line. The output should be exactly the string returned:

  • If the URL is http://example.com and is either not cached or the cache has expired, output Example Domain.
  • If the URL is http://example.com and a valid cache entry exists, output Example Domain (from the cache).
  • For any other URL, output None.
## sample
5
0 http://example.com 3600
2 http://example.com 3600
3 http://nonexistent-domain.com 3600
5 http://example.com 2
6 http://example.com 2
Example Domain

Example Domain None Example Domain Example Domain

</p>