Skip to content

Commit 0e5ddc4

Browse files
committed
Prepended current access token to the hashes created by cache function to allow different initializations of the class to be able to use the cache without conflict. Added arguments to get data function input vars. Implemented a 'skip_read_from_cache' argument for get_data arguments to skip reading a request from the cache
1 parent c561cd1 commit 0e5ddc4

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/API.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,21 @@ public function fetch_page_of_members_from_campaign($campaign_id, $page_size, $c
7373

7474
}
7575

76-
public function get_data($suffix) {
77-
76+
public function get_data( $suffix, $args = array() ) {
77+
7878
// Construct request:
7979
$api_request = $this->api_endpoint . $suffix;
8080

8181
// This identifies a unique request
82-
$api_request_hash = md5($api_request);
82+
$api_request_hash = md5( $this->access_token . $api_request );
8383

8484
// Check if this request exists in the cache and if so, return it directly - avoids repeated requests to API in the same page run for same request string
8585

86-
if ( isset( self::$request_cache[$api_request_hash] ) ) {
87-
return self::$request_cache[$api_request_hash];
88-
}
86+
if ( !isset( $args['skip_read_from_cache'] ) ) {
87+
if ( isset( self::$request_cache[$api_request_hash] ) ) {
88+
return self::$request_cache[$api_request_hash];
89+
}
90+
}
8991

9092
// Request is new - actually perform the request
9193

@@ -144,7 +146,7 @@ private function __create_ch($api_request) {
144146

145147
$headers = array(
146148
'Authorization: Bearer ' . $this->access_token,
147-
'User-Agent: Patreon-PHP, version 1.0.0, platform ' . php_uname('s') . '-' . php_uname( 'r' ),
149+
'User-Agent: Patreon-PHP, version 1.0.1, platform ' . php_uname('s') . '-' . php_uname( 'r' ),
148150
);
149151

150152
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

0 commit comments

Comments
 (0)