Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
helper-3366551
Manage
Activity
Members
Labels
Plan
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Issue forks
helper-3366551
Commits
d5e5f762
Commit
d5e5f762
authored
11 years ago
by
Dave Reid
Browse files
Options
Downloads
Patches
Plain Diff
Added a HttpHelper for caching drupal_http_requests().
parent
93522bf7
No related branches found
Branches containing commit
Tags
9.3.3
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
helper.info
+1
-0
1 addition, 0 deletions
helper.info
lib/HttpHelper.php
+35
-0
35 additions, 0 deletions
lib/HttpHelper.php
with
36 additions
and
0 deletions
helper.info
+
1
−
0
View file @
d5e5f762
...
...
@@ -7,6 +7,7 @@ files[] = lib/CacheHelper.php
files[] = lib/EntityHelper.php
files[] = lib/FeaturesHelper.php
files[] = lib/FieldHelper.php
files[] = lib/HttpHelper.php
files[] = lib/RenderHelper.php
files[] = includes/HelperDebugMailLog.php
files[] = views/views_handler_field_helper_entity_operation_links.inc
This diff is collapsed.
Click to expand it.
lib/HttpHelper.php
0 → 100644
+
35
−
0
View file @
d5e5f762
<?php
class
HttpHelper
{
public
static
function
cachedRequest
(
$url
,
array
$options
=
array
(),
$cache_errors
=
FALSE
)
{
$cid
=
static
::
cachedRequestGetCid
(
$url
,
$options
);
$bin
=
isset
(
$options
[
'cache'
][
'bin'
])
?
$options
[
'cache'
][
'bin'
]
:
'cache'
;
if
(
$cid
&&
$cache
=
CacheHelper
::
get
(
$cid
,
$bin
))
{
return
$cache
->
data
;
}
else
{
$response
=
drupal_http_request
(
$url
,
$options
);
if
(
!
$cache_errors
&&
!
empty
(
$response
->
error
))
{
$cid
=
FALSE
;
}
if
(
$cid
)
{
$expire
=
isset
(
$options
[
'cache'
][
'expire'
])
?
$options
[
'cache'
][
'expire'
]
:
CACHE_TEMPORARY
;
cache_set
(
$cid
,
$response
,
$bin
,
$expire
);
}
return
$response
;
}
}
public
static
function
cachedRequestGetCid
(
$url
,
array
$options
)
{
if
(
isset
(
$options
[
'cache'
])
&&
$options
[
'cache'
]
===
FALSE
)
{
return
FALSE
;
}
if
(
isset
(
$options
[
'cache'
][
'cid'
]))
{
return
$options
[
'cache'
][
'cid'
];
}
$cid_parts
=
array
(
$url
,
serialize
(
array_diff_key
(
$options
,
drupal_map_assoc
(
array
(
'cache'
)))));
return
'http-request:'
.
drupal_hash_base64
(
serialize
(
$cid_parts
));
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment