Improved user serialization to use less memory in the session

This commit is contained in:
Matias Griese
2018-11-27 10:15:55 +02:00
parent b6c582ad3a
commit 708c79cef8
3 changed files with 55 additions and 0 deletions

View File

@@ -1,3 +1,9 @@
# v1.5.6
## mm/dd/2018
1. [](#improved)
* Improved user serialization to use less memory in the session
# v1.5.5
## 11/12/2018

View File

@@ -82,4 +82,28 @@ trait CompiledFile
return parent::content($var);
}
/**
* Serialize file.
*/
public function __sleep()
{
return [
'filename',
'extension',
'raw',
'content',
'settings'
];
}
/**
* Unserialize file.
*/
public function __wakeup()
{
if (!isset(static::$instances[$this->filename])) {
static::$instances[$this->filename] = $this;
}
}
}

View File

@@ -286,4 +286,29 @@ class User extends Data
return 'https://www.gravatar.com/avatar/' . md5($this->email);
}
/**
* Serialize user.
*/
public function __sleep()
{
return [
'items',
'storage'
];
}
/**
* Unserialize user.
*/
public function __wakeup()
{
$this->gettersVariable = 'items';
$this->nestedSeparator = '.';
if (null === $this->blueprints) {
$blueprints = new Blueprints;
$this->blueprints = $blueprints->get('user/account');
}
}
}