Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
syncEnrollments
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Yeray Santana Hualde
syncEnrollments
Commits
aff9e194
Commit
aff9e194
authored
Apr 28, 2012
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement sectionable caching in array cache driver.
parent
68d9210e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
110 additions
and
7 deletions
+110
-7
memory.php
laravel/cache/drivers/memory.php
+110
-7
No files found.
laravel/cache/drivers/memory.php
View file @
aff9e194
<?php
namespace
Laravel\Cache\Drivers
;
class
Memory
extends
Driver
{
class
Memory
extends
Driver
implements
Sectionable
{
/**
* The in-memory array of cached items.
...
...
@@ -28,10 +28,22 @@ class Memory extends Driver {
*/
protected
function
retrieve
(
$key
)
{
if
(
array_key_exists
(
$key
,
$this
->
storage
))
{
return
$this
->
storage
[
$key
];
}
return
array_get
(
$this
->
storage
,
$key
);
}
/**
* Retrieve a sectioned item from the cache driver.
*
* @param string $section
* @param string $key
* @param mixed $default
* @return mixed
*/
public
function
get_from_section
(
$section
,
$key
,
$default
=
null
)
{
$key
=
$this
->
section_item_key
(
$section
,
$key
);
return
array_get
(
$this
->
storage
,
$key
,
$default
);
}
/**
...
...
@@ -49,7 +61,21 @@ class Memory extends Driver {
*/
public
function
put
(
$key
,
$value
,
$minutes
)
{
$this
->
storage
[
$key
]
=
$value
;
array_set
(
$this
->
storage
,
$key
,
$value
);
}
/**
* Write a sectioned item to the cache.
*
* @param string $section
* @param string $key
* @param mixed $value
* @param int $minutes
* @return void
*/
public
function
put_in_section
(
$section
,
$key
,
$value
,
$minutes
)
{
$this
->
put
(
$this
->
section_item_key
(
$section
,
$key
),
$value
,
$minutes
);
}
/**
...
...
@@ -64,6 +90,48 @@ class Memory extends Driver {
$this
->
put
(
$key
,
$value
,
0
);
}
/**
* Write a sectioned item to the cache that lasts forever.
*
* @param string $section
* @param string $key
* @param mixed $value
* @return void
*/
public
function
forever_in_section
(
$section
,
$key
,
$value
)
{
$this
->
put_in_section
(
$section
,
$key
,
$value
,
0
);
}
/**
* Get a sectioned item from the cache, or cache and return the default value.
*
* @param string $section
* @param string $key
* @param mixed $default
* @param int $minutes
* @return mixed
*/
public
function
remember_in_section
(
$section
,
$key
,
$default
,
$minutes
,
$function
=
'put'
)
{
$key
=
$this
->
section_item_key
(
$section
,
$key
);
return
$this
->
remember
(
$key
,
$default
,
$minutes
,
$function
);
}
/**
* Get a sectioned item from the cache, or cache the default value forever.
*
* @param string $section
* @param string $key
* @param mixed $default
* @return mixed
*/
public
function
sear_in_section
(
$section
,
$key
,
$default
)
{
return
$this
->
sear
(
$this
->
section_item_key
(
$section
,
$key
),
$default
);
}
/**
* Delete an item from the cache.
*
...
...
@@ -72,7 +140,30 @@ class Memory extends Driver {
*/
public
function
forget
(
$key
)
{
unset
(
$this
->
storage
[
$key
]);
array_forget
(
$this
->
storage
,
$key
);
}
/**
* Delete a sectioned item from the cache.
*
* @param string $section
* @param string $key
* @return void
*/
public
function
forget_in_section
(
$section
,
$key
)
{
$this
->
forget
(
$this
->
section_item_key
(
$section
,
$key
));
}
/**
* Delete an entire section from the cache.
*
* @param string $section
* @return int|bool
*/
public
function
forget_section
(
$section
)
{
array_forget
(
$this
->
storage
,
'section#'
.
$section
);
}
/**
...
...
@@ -85,4 +176,16 @@ class Memory extends Driver {
$this
->
storage
=
array
();
}
/**
* Get a section item key for a given section and key.
*
* @param string $section
* @param string $key
* @return string
*/
protected
function
section_item_key
(
$section
,
$key
)
{
return
"section#
{
$section
}
.
{
$key
}
"
;
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment