Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
open-source
MetaGer
Commits
962ff43e
Commit
962ff43e
authored
Sep 30, 2021
by
Dominik Hebeler
Browse files
Fill Cache command no longer needed
parent
652dd88f
Changes
1
Hide whitespace changes
Inline
Side-by-side
app/Console/Commands/FillCache.php
deleted
100644 → 0
View file @
652dd88f
<?php
namespace
App\Console\Commands
;
use
Illuminate\Console\Command
;
use
Cache
;
class
FillCache
extends
Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected
$signature
=
'cache:fill'
;
/**
* The console command description.
*
* @var string
*/
protected
$description
=
'Command description'
;
/**
* Create a new command instance.
*
* @return void
*/
public
function
__construct
()
{
parent
::
__construct
();
}
/**
* Execute the console command.
*
* @return int
*/
public
function
handle
()
{
$writtenBytes
=
0
;
$lastStatus
=
microtime
(
true
);
while
(
true
)
{
$key
=
$this
->
getRandomString
(
rand
(
50
,
100
));
$value
=
$this
->
getRandomString
(
rand
(
1024
*
100
,
1024
*
10000
));
Cache
::
put
(
$key
,
$value
);
$writtenBytes
+=
mb_strlen
(
Cache
::
get
(
$key
));
if
(
microtime
(
true
)
-
$lastStatus
>
1
){
echo
"Stored "
.
$this
->
formatBytes
(
$writtenBytes
)
.
"."
.
PHP_EOL
;
$lastStatus
=
microtime
(
true
);
}
}
return
0
;
}
function
getRandomString
(
$n
)
{
$characters
=
'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
;
$randomString
=
''
;
for
(
$i
=
0
;
$i
<
$n
;
$i
++
)
{
$index
=
rand
(
0
,
strlen
(
$characters
)
-
1
);
$randomString
.
=
$characters
[
$index
];
}
return
$randomString
;
}
function
formatBytes
(
$bytes
,
$precision
=
2
)
{
$units
=
array
(
'B'
,
'KiB'
,
'MiB'
,
'GiB'
,
'TiB'
);
$bytes
=
max
(
$bytes
,
0
);
$pow
=
floor
((
$bytes
?
log
(
$bytes
)
:
0
)
/
log
(
1024
));
$pow
=
min
(
$pow
,
count
(
$units
)
-
1
);
// Uncomment one of the following alternatives
// $bytes /= pow(1024, $pow);
$bytes
/=
(
1
<<
(
10
*
$pow
));
return
round
(
$bytes
,
$precision
)
.
' '
.
$units
[
$pow
];
}
}
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