×
Community Blog Expand Your HTML Page File Cache with Cloud Storage

Expand Your HTML Page File Cache with Cloud Storage

Caching is crucial for websites and can solve most complex performance issues. In this article, we will explain how to use Alibaba Cloud OSS to solve the problem of insufficient HTML cache space.

ST_003

Background

Most people use cloud storage apps, such as Object Storage Service (OSS), for images or other large files. However, cloud storage is not intrinsically limited to a single use case but merely provides a platform for us to solve a wide range of problems. In this article, we will explain how to use Alibaba Cloud OSS to solve the problem of insufficient HTML cache space.

Caching is crucial for websites and can solve most complex performance issues. There are many types of cache, the most common ones being the memory cache and the disk cache (page cache). Memory cache is quicker and is typically used to store critical and hot content, but it cannot be used to store large amounts of data. Disk cache on the other hand is much slower because it employs disk I/O. However, the disk cache can be used for performing complex database queries, processing business logic, and accelerating page loading.

Scenario

In this example, several hundred GBs of HTML page file cache data is generated every day. What will happen if we put all of these files directly onto a hard drive?

  1. The hard drive space will be insufficient. Although drive space is relatively cheap, it is difficult to predict how much space your app will require as your business grows. You could potentially store these files on several drives, but that will make management more difficult.
  2. The HTML file cache may expire, at which point it needs to be removed to free up drive space. The deletion of several hundred GBs of small files, however, will create high I/O loads, seriously affecting web services.

Solution

We can use OSS to store these small HTML page files. The advantages of using OSS are:

  1. You do not need to worry about affecting the host web services when removing expired files. Scripts are run regularly every day to delete expired files on the OSS and to release space.
  2. OSS and ECS are interconnected over the intranet without any Internet traffic involved, significantly reducing network latency. Despite the network traffic, response time will be limited to within 100 ms.
  3. The OSS response header can be used as an effective means of cache control.

Uploading and Removing Files on OSS

Step 1: Activate OSS

Before using Alibaba Cloud OSS service, ensure that you have registered for an Alibaba Cloud account and completed real-name authentication. If you do not have an Alibaba Cloud account yet, the system will prompt you to register for an account when you activate OSS.

Process

  1. Log on to the Alibaba Cloud official website.
  2. Go to the OSS Product Detail Page and click Activate Now.
  3. After OSS service is activated, click Console to access the OSS console interface.
    You can also click Console in the upper-right menu bar on the homepage to access the Alibaba Cloud console, and click on the button shown in the figure below to access the OSS console interface.

Step 2: Create a bucket

After you activate Alibaba Cloud OSS service, you need to use the OSS console to create a bucket for storing files.

Process

  1. Go to the OSS console interface.
  2. Click Manage Buckets > New Bucket to open the New Bucket dialog box.
  3. In the Bucket Name field, enter the name of your bucket. The bucket name must comply with the naming rules and must be unique among all existing bucket names in Alibaba Cloud OSS. The bucket name may not be changed after being created. For more information about bucket naming, refer to OSS Basic Concepts.
  4. In the Region drop-down box, select the data center of the bucket. The region may not be changed after being subscribed. To access the OSS through the ECS Intranet, you can select the same region as your ECS for the bucket. For more information about regions, refer to Regions and Endpoints in the Alibaba Cloud OSS Developer Guide.
  5. In the ACL drop-down box, select an access permission for the bucket.
    Public Read/Write: Any users (including anonymous users) can perform read, write, and delete operations on the objects in the bucket. The fees incurred by these operations will be borne by the creator of the bucket. Use this permission with caution.

Public Read: Only the creator of the bucket can perform write and delete operations on the objects in the bucket. Any users (including anonymous users) can read the objects in the bucket.
Private: Only the creator of the bucket can perform read, write, and delete operations on the objects in the bucket. Other users cannot access the objects in the bucket without authorization.

  1. Click Submit. The bucket is successfully created.

Step 3: Upload a file

After you create a bucket, you can upload all types of files to the bucket. Using the OSS console, you can upload files smaller than 5 GB. For details about how to upload files larger than 5 GB, refer to Multipart Upload in the Alibaba Cloud OSS Developer Guide.

Process

  1. Go to the OSS console interface.
  2. Click on the name of your desired bucket to open the bucket management page.
  3. Click Manage Objects to open the object management page of the bucket.
  4. Click Upload File to open the file selection dialog box.
  5. Select the file you want to upload and click Open. After the file has been uploaded successfully, click Refresh to view the uploaded file.

Step 4: Delete an object

If you do not need to store an uploaded object any longer, you can delete it to avoid further charges. You can delete a single object or delete multiple objects in batches in the OSS console.

Process

  1. Go to the OSS console interface.
  2. Click on the name of the bucket that contains the object to be deleted to open the bucket management page.
  3. Click Manage Objects to open the object management page.
  4. Click the Delete link of the target object.
  5. Click OK to delete the object. To delete objects in batches, select the objects to be deleted and click Batch Delete. You can delete up to 50 objects at a time in the OSS console. For more flexible selection methods, refer Delete and Object in the Alibaba Cloud OSS Developer Guide.

Summary

In this article, we introduced the problems with conventional caching methods and discussed the method of using OSS to cache HTML files. With OSS, you do not have to worry about disk space limitations or high server loads from deleting multiple expired files. At less than five Chinese yuan a day, OSS is a cost effective solution to all your file storage needs. Try it today!

0 0 0
Share on

Alibaba Clouder

2,599 posts | 764 followers

You may also like

Comments