Skip to content
This repository was archived by the owner on Jun 19, 2020. It is now read-only.

Commit d50b629

Browse files
hlr1983jefleponot
authored andcommitted
clearMemoryCache() + clearCache() + Docs
1 parent 01bdcf3 commit d50b629

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

docs/modules/casper.rst

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,54 @@ Think of it as a way to stop javascript execution within the remote DOM environm
667667

668668
casper.run();
669669

670+
.. _casper_clearcache:
671+
672+
.. index:: Memory
673+
674+
``clearCache()``
675+
-------------------------------------------------------------------------------
676+
677+
**Signature:** ``clearCache()``
678+
679+
.. versionadded:: 1.1.5
680+
681+
Replace current page by a new page object, with newPage() and clear the memory cache, with clearMemoryCache().
682+
Example::
683+
684+
casper.start('http://www.google.fr/', function() {
685+
this.clearCache(); // cleared the memory cache and replaced page object with newPage().
686+
});
687+
688+
casper.then(function() {
689+
// ...
690+
});
691+
692+
casper.run();
693+
694+
.. _casper_clearmemorycache:
695+
696+
.. index:: Memory
697+
698+
``clearMemoryCache()``
699+
-------------------------------------------------------------------------------
700+
701+
**Signature:** ``clearMemoryCache()``
702+
703+
.. versionadded:: 1.1.5
704+
705+
Use the engine page.clearMemoryCache() to clear the memory cache.
706+
Example::
707+
708+
casper.start('http://www.google.fr/', function() {
709+
this.clearMemoryCache(); // cleared the memory cache.
710+
});
711+
712+
casper.then(function() {
713+
// ...
714+
});
715+
716+
casper.run();
717+
670718
.. index:: Debugging
671719

672720
``debugHTML()``

modules/casper.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,39 @@ Casper.prototype.clear = function clear() {
464464
return this;
465465
};
466466

467+
/**
468+
* Replace currente page by a new page object, with newPage()
469+
* Clears the memory cache, with clearMemoryCache()
470+
*
471+
* @return Casper
472+
*/
473+
Casper.prototype.clearCache = function clearCache() {
474+
"use strict";
475+
this.checkStarted();
476+
this.page = this.newPage();
477+
this.clearMemoryCache();
478+
return this;
479+
};
480+
481+
/**
482+
* Clears the memory cache, using engine method
483+
* reference: https://github.com/ariya/phantomjs/issues/10357
484+
*
485+
* @return Casper
486+
*/
487+
Casper.prototype.clearMemoryCache = function clearMemoryCache() {
488+
"use strict";
489+
this.checkStarted();
490+
if (typeof this.page.clearMemoryCache === 'function') {
491+
this.page.clearMemoryCache();
492+
} else if ( phantom.casperEngine === 'slimerjs' || utils.matchEngine({name: 'phantomjs', version: {min: '2.0.0'}}) ) {
493+
this.log('clearMemoryCache() did nothing: page.clearMemoryCache is not avliable in this engine', "warning");
494+
} else {
495+
throw new CasperError("clearMemoryCache(): page.clearMemoryCache should be avaliable in this engine");
496+
};
497+
return this;
498+
};
499+
467500
/**
468501
* Emulates a click on the element from the provided selector using the mouse
469502
* pointer, if possible.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy