Efficient advertisement platform IP information caching method based on byte array

By using a byte array-based caching method, the performance and cost issues of existing IP address lookup caching schemes are resolved, achieving efficient and low-memory IP information caching, and reducing external API calls and backend service pressure.

CN121644516APending Publication Date: 2026-03-10XIAN DIANGAO NET TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-11-18
Publication Date
2026-03-10

AI Technical Summary

Technical Problem

Existing IP address lookup caching solutions suffer from high response latency, limited concurrent processing capabilities, high costs, and heavy pressure on backend services. In particular, they are inadequate in terms of storage costs and data structure design when using general-purpose caching systems such as Redis.

Method used

A byte array-based caching method is adopted. By sorting the abbreviation codes of countries/regions around the world in alphabetical order and assigning them unique serial numbers, a country mapping table is constructed. IPv4 addresses are converted into 32-bit binary numbers and then into decimal serial numbers. A byte array of length 2³² is used to store 8-bit encoded serial numbers with decimal serial numbers as array subscripts, thereby achieving efficient IP information caching.

Benefits of technology

Storing global IPv4 geolocation information in a small amount of memory reduces memory usage, lowers cache rebuild time, improves query response speed, reduces the number of external API calls and backend service pressure, and reduces costs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121644516A_ABST
    Figure CN121644516A_ABST
Patent Text Reader

Abstract

The invention discloses an efficient advertisement platform IP information caching method and device based on a byte array, and the method comprises the steps: sorting abbreviation codes of global countries / regions according to a letter order, and distributing unique serial numbers to obtain a country mapping table; the IPv4 address is converted into a corresponding 32-bit binary number, and then the 32-bit binary number is converted into a decimal serial number; based on the country mapping table, converting country / region information corresponding to the IPv4 address into a 8-bit coding sequence number; and constructing a byte array with the length of 2, taking a decimal serial number as an array subscript, and storing the 8-bit coding serial number to an array position corresponding to the subscript in a byte type. According to the method, the byte array design of global IPv4 geographical location information can be stored by a small amount of memory, and the cached IP geographical location information can be conveniently persisted to the disk by only using a small amount of memory, so that cache reconstruction is conveniently carried out.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of network, in particular to an efficient advertising platform IP information caching method and device based on byte array. BACKGROUND

[0002] IP address query service plays an important role in user behavior analysis, precision marketing and other fields. At present, mainstream IP address query service providers (such as IP2Location, MaxMind, etc.) provide IP geographic location information query service through API interface. However, direct calling of these external API interfaces has problems such as high response delay, limited concurrent processing capacity, high cost, great pressure on backend service, etc. In order to solve these problems, the industry generally adopts caching mechanism to optimize IP query performance.

[0003] In the prior art, common IP query caching schemes include using Redis, Memcached and other distributed caching systems. Although these schemes can improve query performance, they still have deficiencies in storage cost, data structure design, cache persistence, etc.

[0004] For example, general caching systems such as Redis use simple key-value storage method when storing a large amount of IP address information, store IP addresses as keys and geographic location information as values in the cache, which occupies a lot of memory; after system restart, due to high memory occupation, cache reconstruction takes a long time. SUMMARY

[0005] The main purpose of the present application is to provide an efficient advertising platform IP information caching method and device based on byte array, which aims to store the byte array design of global IPv4 geographic location information relying on a small amount of memory.

[0006] To achieve the above purpose, the present application provides an efficient advertising platform IP information caching method based on byte array, comprising: sorting and assigning unique serial numbers to the abbreviation codes of countries / regions in the world according to alphabetical order to obtain a country mapping table; converting the IPv4 address into a corresponding 32-bit binary number, and then converting the 32-bit binary number into a decimal serial number; based on the country mapping table, converting the country / region information corresponding to the IPv4 address into an 8-bit code serial number; constructing a byte array with a length of 2^32, taking the decimal serial number as the array subscript, and storing the 8-bit code serial number in byte type to the array position corresponding to the subscript.

[0007] Optionally, the method further comprises: In response to the IP information query request, the queried IPv4 address is converted into a decimal serial number, the corresponding 8-bit encoded serial number is accessed through the serial number, and the country / region information is decoded through the country mapping table and returned.

[0008] Optionally, the country mapping table comprises a forward mapping table and a reverse mapping table. The forward mapping table takes country / region abbreviation codes as keys and corresponding serial numbers as values. The reverse mapping table takes serial numbers as keys and country / region information as values.

[0009] Optionally, the conversion of the IPv4 address into a corresponding 32-bit binary number and then into a decimal serial number comprises: The dotted decimal representation of the IPv4 address is evenly split into four parts according to length, each part is converted into an 8-bit binary number, the four 8-bit binary numbers are spliced to obtain a 32-bit binary number, the 32-bit binary number is converted into a decimal number, and the decimal serial number corresponding to the IPv4 address is obtained.

[0010] Optionally, the 8-bit encoded serial number ranges from 0 to 249, and the 8-bit encoded serial number and the unique serial number of the country / region correspond to each other.

[0011] Optionally, the method further comprises: When querying the country / region information of the target IPv4 address for the first time, the country / region information corresponding to the IPv4 address is obtained from an external IP service provider, the country / region information is converted into an 8-bit encoded serial number through the country mapping table, and the 8-bit encoded serial number is stored in the corresponding subscript position of the byte array.

[0012] Optionally, the conversion of the country / region information into an 8-bit encoded serial number comprises: The low 8-bit value of the unique serial number of the country / region is obtained through bit operation & 0xffff, and is taken as the 8-bit encoded serial number.

[0013] Optionally, the country / region information comprises country / region names and corresponding alpha2 abbreviation codes, and the reverse mapping table is used to decode the 8-bit encoded serial number into the corresponding country / region names and alpha2 abbreviation codes.

[0014] In addition, to achieve the above-mentioned purpose, the application also provides a high-efficiency advertising platform IP information caching device based on a byte array, comprising: A mapping table construction module is configured to sort the abbreviation codes of countries / regions around the world in alphabetical order and assign unique serial numbers to obtain a country mapping table. The address translation module is used to convert IPv4 addresses into corresponding 32-bit binary numbers, and then convert the 32-bit binary numbers into decimal serial numbers; The encoding module is used to convert the country / region information corresponding to the IPv4 address into an 8-bit encoded sequence number based on the country mapping table. The storage module is used to construct a byte array of length 2³², using a decimal index as the array subscript, and storing the 8-bit encoded index as a byte in the array position corresponding to that index.

[0015] This application proposes a method and apparatus for efficient IP information caching on an advertising platform based on a byte array. The method involves sorting global country / region abbreviations alphabetically and assigning unique serial numbers to them, thus obtaining a country mapping table. IPv4 addresses are converted into corresponding 32-bit binary numbers, and then these 32-bit binary numbers are converted into decimal serial numbers. Based on the country mapping table, the country / region information corresponding to the IPv4 address is converted into an 8-bit encoded serial number. A byte array of length 2³² is constructed, using the decimal serial number as the array index, and the 8-bit encoded serial number is stored as a byte in the array position corresponding to that index. This application utilizes a byte array design that can store global IPv4 geographic location information with minimal memory usage. Because only a small amount of memory is used, the cached IP geographic location information can be easily persisted to disk, facilitating cache rebuilding. Attached Figure Description

[0016] Figure 1 This is a flowchart illustrating an embodiment of the efficient advertising platform IP information caching method based on byte arrays provided in this application; Figure 2 This is a Map diagram of the reverse mapping table provided in an embodiment of the efficient advertising platform IP information caching method based on byte arrays in this application.

[0017] The realization of the purpose, functional features and advantages of this application will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation

[0018] It should be understood that the specific embodiments described herein are merely illustrative of this application and are not intended to limit this application.

[0019] Reference Figure 1 In one embodiment of this application, a method for efficient IP information caching of an advertising platform based on byte arrays includes four steps: S101, S102, S103, and S104, as detailed below: S101. Sort the abbreviation codes of countries / regions worldwide alphabetically and assign them unique serial numbers to obtain a country mapping table. Among the information frequently used in advertising platforms is IP geolocation information, such as country information. There are approximately 200 countries and regions globally, each with its own abbreviation code (e.g., alpha2 abbreviation code). By sorting these country abbreviation codes alphabetically and assigning a unique number to each abbreviation code, a country mapping table can be formed. For example, the first five country information digits and their corresponding numbers are as follows: the alpha2 abbreviation code for the country Andorra is "AD," assigned number 0; the alpha2 abbreviation code for the country United Arab Emirates is "AE," assigned number 1; the alpha2 abbreviation code for the country Afghanistan is "AF," assigned number 2; the alpha2 abbreviation code for the country Antigua and Barbuda is "AG," assigned number 3; the alpha2 abbreviation code for the country Anguilla is "AI," assigned number 4, and so on until all countries / regions have been sorted and assigned numbers.

[0020] Clearly, by sorting countries alphabetically and assigning unique serial numbers to build a country mapping table, a fixed correspondence between country / region abbreviation codes and serial numbers can be established. This lays the foundation for converting country / region information into concise coded serial numbers and avoids errors in subsequent caching and querying due to a chaotic correspondence.

[0021] Corresponding to the indices 0, 1, 2, 3, and 4 above, they can be encoded in binary as 0, 1, 10, 11, and 100. Taking Java as an example, a Map data type can be used to construct the mapping table, where the key is the country code and the value is the corresponding indices. The above country information can be represented as: (AD,0)(AE,1)(AF,2)(AG,3)(AI,4) The above process maps country information to specific serial numbers. Similarly, the last country serial number, 249, corresponds to the binary code 11111001. It can be observed that a maximum of 8 bits are used; that is, 8 bits are sufficient to represent the serial numbers of all countries. Therefore, the country information corresponding to each IPv4 address can be identified using 8 bits of data, which is 1 byte.

[0022] S102. Convert the IPv4 address into its corresponding 32-bit binary number, and then convert the 32-bit binary number into a decimal sequence number. In one embodiment of this application, the step of converting the IPv4 address into a corresponding 32-bit binary number and then converting the 32-bit binary number into a decimal number includes: splitting the dotted decimal representation of the IPv4 address into four parts of equal length, converting each part into an 8-bit binary number, concatenating the four 8-bit binary numbers to obtain a 32-bit binary number, and then converting the 32-bit binary number into a decimal number to obtain the decimal number corresponding to the IPv4 address.

[0023] IPv4 addresses are typically expressed in dotted decimal notation (e.g., 1.1.1.1). In this notation, the IPv4 address is divided into four parts by ".", each part being a decimal digit. Specifically, since each decimal digit can be represented by an 8-bit binary number, after converting each part of the IPv4 address to an 8-bit binary number, removing the ".", and concatenating the four 8-bit binary numbers, a 32-bit binary number is obtained. This 32-bit binary number is then converted back to a decimal number, which is the decimal sequence number corresponding to the IPv4 address. For example, taking the IPv4 address 1.1.1.1 as an example, its four parts in dotted decimal are 1, 1, 1, 1. Each part is converted into an 8-bit binary number, which is 00000001, 00000001, 00000001, 00000001. After concatenation, we get a 32-bit binary number 00000001000000010000000100000001. Then, we convert this 32-bit binary number back to decimal, and the result is 16843009. That is, the decimal sequence number corresponding to the IPv4 address 1.1.1.1 is 16843009. According to the above calculation method, the total number of IPv4 addresses in the world is 2^32, approximately 4,294,967,296. Therefore, for the total number of IPv4 addresses, a 2^32 byte array can be used to store the global IPv4 country information. In a single machine scenario, only about 4GB of memory is required.

[0024] In fact, by converting IPv4 addresses to decimal serial numbers, a unique "identifier" can be assigned to each IPv4 address. This identifier can be directly used as an index in subsequent byte arrays, achieving a precise correspondence between IPv4 addresses and byte array storage locations, thus avoiding storage conflicts between different IPv4 addresses in the cache. With this design, any small, enumerable amount of data can be cached with low memory usage.

[0025] S103. Based on the country mapping table, convert the country / region information corresponding to the IPv4 address into an 8-bit encoded sequence number.

[0026] In one embodiment of this application, the efficient advertising platform IP information caching method based on byte array further includes: in response to an IP information query request, converting the queried IPv4 address into a decimal sequence number, accessing the byte array through the sequence number to obtain the corresponding 8-bit encoded sequence number, and then decoding the country / region information through the country mapping table and returning it.

[0027] In one embodiment of this application, the value range of the 8-bit encoded sequence number is 0~249, and the 8-bit encoded sequence number corresponds one-to-one with the unique sequence number of the country / region.

[0028] Once the country / region information corresponding to a certain IPv4 address is obtained (e.g., through an external IP service provider), the aforementioned country mapping table can be queried to find the unique serial number corresponding to that country / region information. Since there are only more than 200 countries / regions in the world, the maximum value of its corresponding unique serial number is 249, and the binary code corresponding to 249 is 11111001 (8 bits in total). Therefore, this unique serial number can be directly used as the 8-bit encoding serial number, that is, the 8-bit encoding serial number corresponding to the country / region information is consistent with the unique serial number in the country mapping table.

[0029] Converting country / region information into an 8-bit encoded sequence number can significantly reduce the storage size of country / region information. Information such as country / region names and abbreviation codes, which may have previously required multiple bytes to store, can now be represented by only 1 byte (8 bits), creating conditions for a significant reduction in the memory usage of the cache in the future.

[0030] In one embodiment of this application, the step of converting country / region information into an 8-bit encoded sequence number includes: obtaining the lower 8 bits of the unique country / region sequence number through the bit operation &0xffff, and using it as the 8-bit encoded sequence number.

[0031] Specifically, in some programming languages ​​(such as Java), integer types are typically 32-bit or 64-bit. When a country / region's unique serial number is stored as an integer, its higher-order bits (the part exceeding 8 bits) may contain invalid values ​​(such as 0). In this case, the lower 8 bits of the integer can be filtered out using the bitwise operation "&0xffff"—where 0xffff is a hexadecimal number, corresponding to 16 ones in binary. After performing an AND operation with the integer, the result only retains the lower 16 bits of the integer. However, since the maximum unique serial number for a country / region is 249 (only 8 bits), the higher 8 bits of its lower 16 bits are all 0. Therefore, the final result is equivalent to retaining the lower 8 bits, which is the 8-bit encoded serial number. For example, if the unique country / region code is 238 (decimal), its 32-bit binary representation is 00000000000000000000000011101110. After performing an "&" operation with 0xffff (binary 00000000000000011111111111111111), the result is 000000000000000000000000011101110, and the lower 8 bits are 11101110 (i.e., 238), which is used as the 8-bit encoded code number. To be precise, obtaining the lower 8 bits through the bit operation "&0xffff" ensures that regardless of the integer type in which the unique country / region serial number is stored, the final 8-bit encoded serial number will only contain the valid lower 8 bits, avoiding encoding errors caused by interference from higher bit values. At the same time, bit operations are low-level operations with extremely fast execution speed, which will not increase the time consumption of the encoding process and ensure the efficiency of cache storage.

[0032] S104. Construct a byte array of length 2³², using the decimal index as the array subscript, and store the 8-bit encoded index as a byte in the array position corresponding to the index.

[0033] The total number of global IPv4 addresses is 2³² (approximately 4,294,967,296). Therefore, constructing a byte array of length 2³² ensures that each IPv4 address has a corresponding array location. Since each array element stores an 8-bit encoded sequence number (occupying 1 byte), the total storage capacity of this byte array is 2³² bytes, or approximately 4GB, which can meet the storage requirements on a single machine. Once the decimal sequence number (e.g., 16843009) and 8-bit encoded sequence number (e.g., 0) corresponding to a certain IPv4 address are determined, the 8-bit encoded sequence number is stored as a byte in the byte array at the position indicated by the following decimal sequence number: byte array [16843009] = (byte)0.

[0034] Specifically, when a client initiates an IP information query request (to query the country / region information of a specific IPv4 address), it first performs the same operation as in S102, converting the queried IPv4 address into a corresponding decimal sequence number. Then, it accesses the byte array based on this decimal sequence number. If the corresponding index position in the byte array already stores an 8-bit encoded sequence number (i.e., the country / region information of the IPv4 address is cached), it directly reads the 8-bit encoded sequence number. Next, it queries the reverse mapping table in the country mapping table (with the sequence number as the key and the country / region information as the value), inputs the 8-bit encoded sequence number, and decodes it to obtain the corresponding country / region information (such as name, alpha2 abbreviation code). Finally, it returns the country / region information to the client.

[0035] For example, if the IPv4 address being queried is 0.0.0.1, its decimal index is 1, and the 8-bit encoded index stored in the byte array [1] is 0, then querying the reverse mapping table will show that index 0 corresponds to the country Andorra (alpha2 abbreviation code AD), and the country information will be returned. Undoubtedly, this query process is entirely based on accessing the local byte array index and decoding the mapping table. It does not require calling the API interface of an external IP service provider, nor does it require complex cache lookup logic. This significantly reduces the response latency of IP information queries, while avoiding increased costs and backend service pressure caused by frequent calls to external APIs.

[0036] In one embodiment of this application, the country mapping table includes a forward mapping table and a reverse mapping table; wherein, the forward mapping table uses country / region abbreviation codes as keys and corresponding serial numbers as values; the reverse mapping table uses serial numbers as keys and country / region information as values.

[0037] In one embodiment of this application, the country / region information includes the country / region name and the corresponding alpha2 abbreviation code, and the reverse mapping table is used to decode the 8-bit encoded sequence number into the corresponding country / region name and alpha2 abbreviation code.

[0038] The country / region information includes both the "country / region name" and the "alpha2 abbreviation code" because these two types of information are the most commonly used content in IP information queries on advertising platforms. The country / region name is used for intuitive display (such as displaying "China" and "United States" in user behavior analysis reports), while the alpha2 abbreviation code is used for standardized identification (such as using "CN" and "US" as country identifiers in precision marketing systems). The combination of the two can meet the diverse needs of advertising platforms.

[0039] Specifically, the purpose of a forward mapping table is to "convert country / region abbreviation codes into serial numbers". For example, when constructing a forward mapping table using the Map data type in Java, its key-value pair format is (AD,0), (AE,1), (AF,2), (AG,3), (AI,4), etc. When the country / region abbreviation code is known, the corresponding serial number can be quickly obtained through the forward mapping table.

[0040] refer to Figure 2 The reverse mapping table's function is to "convert serial numbers into country / region information." Similarly, when constructed using the Java Map data type, its key-value pair format is: (0,{"name":"Andorra","alpha2":"AD"}) (1,{"name":"UnitedArabEmirates","alpha2":"AE"}) (2,{"name":"Afghanistan","alpha2":"AF"}) (3,{"name":"AntiguaandBarbuda","alpha2":"AG"}) (4,{"name":"Anguilla","alpha2":"AI"}) When the serial number (i.e., the 8-bit encoded serial number) is known, the corresponding country / region name and alpha2 abbreviation code can be quickly obtained through the reverse mapping table.

[0041] For example, if the country / region abbreviation code corresponding to an IPv4 address is known to be "AG", querying the forward mapping table will yield the sequence number 3; if the 8-bit encoded sequence number is known to be 3, querying the reverse mapping table will yield the country name Antigua and Barbuda and the alpha2 abbreviation code "AG". More precisely, the separate design of the forward and reverse mapping tables enables bidirectional and fast conversion between "country / region information" and "sequence number": the forward mapping table satisfies the "encoding" requirement (converting country / region information into sequence number), while the reverse mapping table satisfies the "decoding" requirement (converting sequence number into country / region information). The combination of these two ensures the efficiency of the encoding and decoding processes in the entire caching scheme, avoiding the low query efficiency that might occur when using a single mapping table for bidirectional conversion.

[0042] Specifically, "dividing into four parts according to length" means splitting the IPv4 address into four parts using "." as the separator, based on the dotted decimal format (e.g., xxxx). The length of each part is determined by the actual decimal number (e.g., IPv4 address 0.0.0.1 is split into "0", "0", "0", and "1"). Since the decimal value range of each part of the IPv4 address is 0-255, and the binary number corresponding to 0-255 can be represented by 8 bits (e.g., decimal 0 corresponds to 8-bit binary 00000000, and decimal 255 corresponds to 8-bit binary 11111111), each part can be converted into a standard 8-bit binary number. For example, the IPv4 address 0.0.0.4 can be split into four parts: "0", "0", "0", and "4". These parts are converted to 8-bit binary numbers: 00000000, 00000000, 00000000, and 00000100. After concatenation, a 32-bit binary number is obtained: 0000000000000000000000000000100. This 32-bit binary number is then converted to decimal, resulting in the number 4. Therefore, the decimal index corresponding to the IPv4 address 0.0.0.4 is 4.

[0043] Clearly, this conversion process fully follows the underlying encoding logic of IPv4 addresses, ensuring that the decimal sequence number of each IPv4 address is unique and conflict-free. At the same time, the conversion process only involves basic operations such as string splitting and number base conversion, with low computational complexity. It can quickly complete the conversion of IPv4 addresses to decimal sequence numbers and will not become a performance bottleneck for the caching scheme.

[0044] In one embodiment of this application, the efficient advertising platform IP information caching method based on byte array further includes: when querying the country / region information of the target IPv4 address for the first time, obtaining the country / region information corresponding to the IPv4 address from an external IP service provider, converting the country / region information into an 8-bit encoded sequence number through the country mapping table, and storing it in the corresponding index position of the byte array.

[0045] "Initial query" refers to a situation where the country / region information of a certain IPv4 address has not yet been stored in the byte array (i.e., the corresponding index position of the byte array is empty or uninitialized). At this time, the information cannot be obtained from the local cache and must rely on the API interface provided by the external IP service provider to obtain the country / region information (such as country name and alpha2 abbreviation code) corresponding to the IPv4 address.

[0046] Optionally, after obtaining the country / region information, the 8-bit encoded sequence number corresponding to the country / region information is found through the country mapping table according to the method in S103 of claim 1, and then the 8-bit encoded sequence number is stored in the byte array at the position with the decimal sequence number of the target IPv4 address as the subscript according to the method in S104, thus completing the first caching of the country / region information of the IPv4 address; when querying the country / region information of the IPv4 address again in the future, it can be directly obtained from the byte array without calling the API interface of the external IP service provider again.

[0047] For example, when querying the IPv4 address 1.1.1.1 for the first time, the country / region information obtained from MaxMind is "UnitedStates" (alpha2 abbreviation code "US"). A query of the country mapping table shows that the unique sequence number corresponding to "US" is X (let's say 238). Therefore, the 8-bit encoded sequence number is 238. The byte array [16843009] (the decimal sequence number of 1.1.1.1) is assigned the value (byte)238, completing the caching. Undoubtedly, this "initial query - external retrieval - local caching" mechanism achieves dynamic cache construction, eliminating the need to pre-load the country / region information of all IPv4 addresses at system startup (avoiding the time-consuming large-scale data loading at startup). Furthermore, by using a single external retrieval and multiple local queries, the number of external API calls is significantly reduced, lowering API usage costs and dependence on external services, while also alleviating the pressure on the backend services of external IP service providers.

[0048] In another embodiment provided in this application, the efficient advertising platform IP information caching method based on byte arrays further includes: Assume that 0.0.0.1\0.0.0.2\0.0.0.3 are the IPv4 addresses of countries with AD (encoded as 0), and 0.0.0.4\0.0.0.5\0.0.0.6 are the IPv4 addresses of countries with AE (encoded as 1).

[0049] For the IPv4 address 0.0.0.1, its corresponding 32-bit binary number is 0000000000000000000000000000001, and its corresponding decimal number is 1. Therefore, the sequence number for 0.0.0.1 is 1. Its country information is AD, and its corresponding code is 00000000. Therefore, storing 00000000 in the first position of the array represents the country of 0.0.0.1 being AD.

[0050] When querying the IPv4 address 0.0.0.1, it is first converted into an IPv4 sequence number, which is 1. From the first position, the code 00000000 is obtained and converted into the country information AD.

[0051] For the IPv4 address 0.0.0.4, its corresponding 32-bit binary number is 0000000000000000000000000000100, which corresponds to the decimal number 4. Therefore, the sequence number for 0.0.0.4 is 4. Its country information is AE, and its corresponding code is 00000001. Therefore, storing 00000001 at the 4th position of the array represents the country of 0.0.0.4 being AE.

[0052] When querying the IPv4 address 0.0.0.4, it is first converted into an IPv4 sequence number, which is 4. From the 4th position, the code 00000001 is obtained and converted into the country information AE.

[0053] Based on the above embodiments, this application also provides a high-efficiency advertising platform IP information caching device based on byte arrays, comprising: The mapping table construction module is used to sort the abbreviation codes of countries / regions around the world alphabetically and assign them unique serial numbers to obtain a country mapping table. The address translation module is used to convert IPv4 addresses into corresponding 32-bit binary numbers, and then convert the 32-bit binary numbers into decimal serial numbers; The encoding module is used to convert the country / region information corresponding to the IPv4 address into an 8-bit encoded sequence number based on the country mapping table. The storage module is used to construct a byte array of length 2³², using a decimal index as the array subscript, and storing the 8-bit encoded index as a byte in the array position corresponding to that index.

[0054] The above are merely preferred embodiments of this application and do not limit the patent scope of this application. Any equivalent structural or procedural transformations made using the content of this application's specification and drawings, or direct or indirect applications in other related technical fields, are similarly included within the patent protection scope of this application.

Claims

1. A method for efficient IP information caching for advertising platform based on byte array, characterized in that, The method comprises the following steps: Sort the abbreviation codes of countries / regions in the world in alphabetical order and assign a unique serial number to obtain a country mapping table; Convert the IPv4 address into a corresponding 32-bit binary number, and then convert the 32-bit binary number into a decimal serial number; Based on the country mapping table, convert the country / region information corresponding to the IPv4 address into an 8-bit code serial number; Construct a byte array with a length of 2^32, use the decimal serial number as the array subscript, and store the 8-bit code serial number in byte type to the array position corresponding to the subscript.

2. The IP information caching method for efficient advertising platform based on byte array as claimed in claim 1, wherein, The method further comprises: In response to an IP information query request, convert the queried IPv4 address into a decimal serial number, access the byte array through the serial number to obtain the corresponding 8-bit code serial number, and then decode the country / region information through the country mapping table and return it.

3. The IP information caching method for efficient advertising platform based on byte array as claimed in claim 1, wherein, The country mapping table comprises a forward mapping table and a reverse mapping table; The forward mapping table takes the country / region abbreviation code as the key and the corresponding serial number as the value; The reverse mapping table takes the serial number as the key and the country / region information as the value.

4. The IP information caching method for efficient advertisement platform based on byte array as claimed in claim 1, wherein, The conversion of the IPv4 address into a corresponding 32-bit binary number, and then the conversion of the 32-bit binary number into a decimal serial number comprises: The IPv4 address represented in dotted decimal notation is evenly split into four parts according to length, each part is converted into an 8-bit binary number, the four 8-bit binary numbers are spliced to obtain a 32-bit binary number, and then the 32-bit binary number is converted into a decimal number to obtain the decimal serial number corresponding to the IPv4 address.

5. The IP information caching method for efficient advertising platform based on byte array as claimed in claim 1, wherein, The value range of the 8-bit code serial number is 0~249, and the 8-bit code serial number corresponds to the unique serial number of the country / region one by one.

6. The IP information caching method for efficient advertising platform based on byte array as claimed in claim 1, wherein, The method further comprises: When querying the country / region information of the target IPv4 address for the first time, obtain the country / region information corresponding to the IPv4 address from an external IP service provider, convert the country / region information into an 8-bit code serial number through the country mapping table, and store it in the subscript position of the byte array.

7. The IP information caching method for high efficient advertising platform based on byte array as claimed in claim 6, wherein, The conversion of the country / region information into an 8-bit code serial number comprises: Obtain the low 8-bit value of the unique serial number of the country / region through bit operation & 0xffff as the 8-bit code serial number.

8. The byte array based high efficient advertising platform IP information cache of claim 3, wherein, The country / region information comprises the country / region name and the corresponding alpha2 abbreviation code, and the reverse mapping table is used to decode the 8-bit code serial number into the corresponding country / region name and alpha2 abbreviation code.

9. A method for IP information caching in an efficient advertising platform based on byte arrays, the method comprising: receiving a request for IP information; determining whether the request is for IP information; and if the request is for IP information, retrieving the IP information from a cache. The method comprises the following steps: A mapping table construction module is configured to sort the abbreviation codes of countries / regions in the world in alphabetical order and assign a unique serial number to obtain a country mapping table; An address conversion module is configured to convert the IPv4 address into a corresponding 32-bit binary number, and then convert the 32-bit binary number into a decimal serial number; An encoding module is configured to convert the country / region information corresponding to the IPv4 address into an 8-bit code serial number based on the country mapping table; A storage module is configured to construct a byte array with a length of 2^32, use the decimal serial number as the array subscript, and store the 8-bit code serial number in byte type to the array position corresponding to the subscript.