K
K
ken30132014-12-01 20:37:28
PHP
ken3013, 2014-12-01 20:37:28

How to convert code from java to php?

In order to organize pagination, the API owner writes an example in Java. In Java I don’t understand anything at all, explain how to understand and implement it in php ??


This article explains how to add a paginating system for hotel list results using the cacheKey and cacheLocation parameters.
Instructions
Use a List or an Array to save the cacheKey and a List or an Array to save the cacheLocation.
For example, you have made the first list request, and you received the response for the first page, which also includes the cacheKey and cacheLocation for the second page.
Make two lists in which you will save the cacheKey and cacheLocation:
List cacheKeyList = new ArrayList();
cacheKeyList.add(cacheKey); // where cacheKey is being received in the Hotel List response and is used for requesting the next page
List cacheLocationList = new ArrayList();
cacheLocationList.add(cacheLocation); // where cacheLocation is being received in the Hotel List response and is used for requesting the next page
By using cacheKeyList[0] and cacheLocationList[0] in your next Hotel List request, you will receive the response for page 2.
Now, for every request that you do, the cache keys and cache locations for every page are being stored in your list, and for example, if you are at page 5 and you want to go at page 3, all you have to do is make a request using cacheKeyList[1] and cacheLocationList[1].
Also, the lists should be reinitialized after about 30 minutes, as the cacheKey and cacheLocation will expire.
In addition to the above example, you will have to shorten the list to the size of the current page you're on because once you use the cache key and the cache location for a previous page than the one you're on, the new cache key and cache location that you will receive for the next page will be different from the one you had for that next page. For example:
You are on page 5 and you saved the cacheKey and cacheLocation for page 6 in cacheKey[4] and cacheLocation[4]. You go to the previous page, which is page 4 using cacheKey[2] and cacheLocation[2]. You now have to delete all the records from the lists that are past [2] (3rd record in the list) before receiving the response of page 4. For example cacheKey[3] and cacheLocation[3] should not exist at this very moment . After this has been done, you will receive the response with page 4 of hotels and the cacheKey and cacheLocation for page 5, which will be added to cacheKey[3] and cacheLocation[3].
In order to get to the first page, you have to make the initial request, without the cacheKey and cacheLocation.
More information
Initial request without cacheKey and cacheLocation - used to request page 1 of hotels
cacheKey[0] , cacheLocation[0] - used to request page 2 of hotels
cacheKey[1] , cacheLocation[1] - used to request page 3 of hotels
cacheKey[ 2] , cacheLocation[2] - used to request page 4 of hotels
................................... ................................................. .........................
cacheKey[n] , cacheLocation[n] - used to request page n+2 of hotels
Notice
Please note that the example provided is written in Java and depending on the developing language you are using, this may not work. This should be used as a reference and not copy/pasted in your application.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
ken3013, 2014-12-01
@ken3013

cacheKey=-5d14faf0:14a06e0f8df:6c74&
cacheLocation=10.186.170.129:7300

A
Armenian Radio, 2014-12-01
@gbg

The service in each response sends new cacheKey and cacheLocation, sending which in response to it in the next request you will receive the next element of the list of hotels.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question