GVKun编程网logo

PHP FLUSH 函数 在IE11中 清除缓存的方法(php清除缓存代码)

3

如果您对PHPFLUSH函数在IE11中清除缓存的方法感兴趣,那么本文将是一篇不错的选择,我们将为您详在本文中,您将会了解到关于PHPFLUSH函数在IE11中清除缓存的方法的详细内容,我们还将为您解

如果您对PHP FLUSH 函数 在IE11中 清除缓存的方法感兴趣,那么本文将是一篇不错的选择,我们将为您详在本文中,您将会了解到关于PHP FLUSH 函数 在IE11中 清除缓存的方法的详细内容,我们还将为您解答php清除缓存代码的相关问题,并且为您提供关于angularjs – $httpBackend.flush()仍然需要超时来定义对象、c# – StreamWriter.Flush()还会调用FileStream.Flush()吗?、Entitymanager.flush()与EntityManager.getTransaction()。commit-我应该首选什么?、FileOutputStream:“ close”方法是否也调用“ flush”?的有价值信息。

本文目录一览:

PHP FLUSH 函数 在IE11中 清除缓存的方法(php清除缓存代码)

PHP FLUSH 函数 在IE11中 清除缓存的方法(php清除缓存代码)

由于IE需要网页至少有4096个字节后才显示,因此要缓存4096,可能使用如下代码:

ob_end_clean();  //清除缓存

ob_implicit_flush(true); //强制显示

echo str_pad(" ", 4096);

for ($i=10; $i>0; $i--) {

echo "".$i."

";

sleep(1); 

}


angularjs – $httpBackend.flush()仍然需要超时来定义对象

angularjs – $httpBackend.flush()仍然需要超时来定义对象

我正在使用Karma对我的AngularJS应用程序进行单元测试,并使用$HttpBackend对后端进行存根.不知何故,flush()方法似乎没有解决我的所有请求,因为控制器中的某些变量仍然未定义.但是,如果我在解决我的期望之前添加超时,它工作正常!

我的控制器:

FeedbackApp.controller('CompetenceCtrl',[ '$scope','$location','Restangular',function CompetenceCtrl($scope,$location,Restangular) {

        $scope.compId = null;
        $scope.index = null;

        Restangular.one('questionnaires',1).get().then(function (q) {
            $scope.questionnaire = q;

            angular.forEach($scope.questionnaire.competences,function (value,key) {
                var compTemp = new models.Competence(value);
                if (!compTemp.finished() && $scope.compId === null) {
                    $scope.compId = compTemp.id;
                    $scope.index = key;
                }
            });
            getCompetence($scope.compId);

        });

        function getCompetence(compId) {
            Restangular.one('questionnaires',1).one('competences',compId).get().then(function (c) {
                $scope.competence = c;
            });
        }
    }]);

我的规格:

'use strict';

describe('Controller: CompetenceCtrl',function () {
    //load the controller's module
    beforeEach(module('360FeedbackApp','mockQuestionnaire','mockCompetences'));

    var $httpBackend,$scope,createController;

    beforeEach(inject(function ($injector,_Restangular_,defaultQuestionnaire,defaultCompetences) {
        // Set up the mock http service responses
        $httpBackend = $injector.get('$httpBackend');
        // backend deFinition common for all tests
        $httpBackend.whenGET(apiUrl + '/questionnaires/1').respond(defaultQuestionnaire);

        $httpBackend.whenGET(apiUrl + '/questionnaires/1/competences/1').respond(defaultCompetences.competences[0]);
        $httpBackend.whenGET(apiUrl + '/questionnaires/1/competences/2').respond(defaultCompetences.competences[1]);
        $httpBackend.whenGET(apiUrl + '/questionnaires/1/competences/3').respond(defaultCompetences.competences[2]);
        $httpBackend.whenGET(apiUrl + '/questionnaires/1/competences/4').respond(defaultCompetences.competences[3]);
        $httpBackend.whenGET(apiUrl + '/questionnaires/1/competences/5').respond(defaultCompetences.competences[4]);

        $httpBackend.whenPUT(apiUrl + '/questionnaires/1/competences/1').respond(200);
        $httpBackend.whenPUT(apiUrl + '/questionnaires/1/competences/2').respond(200);
        $httpBackend.whenPUT(apiUrl + '/questionnaires/1/competences/3').respond(200);
        $httpBackend.whenPUT(apiUrl + '/questionnaires/1/competences/4').respond(200);
        $httpBackend.whenPUT(apiUrl + '/questionnaires/1/competences/5').respond(200);

        // Get hold of a scope (i.e. the root scope)
        $scope = $injector.get('$rootScope');
        // and the location
        $location = $injector.get('$location');
        // The $controller service is used to create instances of controllers
        var $controller = $injector.get('$controller');

        createController = function () {
            return $controller('CompetenceCtrl',{'$scope': $scope,'$location': $location,'Restangular': _Restangular_ });
        };
    }));

    afterEach(function () {
        $httpBackend.verifyNoOutstandingExpectation();
        $httpBackend.verifyNoOutstandingRequest();
    });

    it('should set the first competence',function () {
        $httpBackend.expectGET(apiUrl + '/questionnaires/1/competences/1');
        createController();
        $httpBackend.flush();
        //DO NOT UNDERSTAND WHY I NEED THIS TIMEOUT! 
        //THE TEST FAILS WITH 'undefined' IF I DONT USE IT!
        setTimeout(function() {
        expect($scope.competence).tobedefined();
        },5000);
    });

任何帮助是极大的赞赏!

解决方法

当你有需要解决的promise(由Restangular调用上的.then()指示)时,你需要在$httpBackend.flush()之后调用$scope.$digest()来解决它们.这听起来也许你的Restangular调用正在击中实际的服务器而不是模拟,这将导致你需要超时.

c# – StreamWriter.Flush()还会调用FileStream.Flush()吗?

c# – StreamWriter.Flush()还会调用FileStream.Flush()吗?

我有一个StreamWriter,其底层流是一个FileStream.以下代码是否保证FileStream还将其缓冲区刷新到文件系统上的实际文件中,或者我是否需要在FileStream上显式调用Flush()?
using (var fs = new FileStream("blabla",FileMode.Append)) {
    using (var sw = new StreamWriter(fs)) {
        sw.WriteLine("Hello,I want to be flushed.");
        sw.Flush(); //I need this to also flush onto the file,not just to the FileStream
    }
}

根据MSDN,“刷新流不会刷新其底层编码器,除非您明确调用Flush或Close”,但我不知道FileStream是否可以被视为“底层编码器”.

另外,如果我没有指定FileOptions.WriteThrough,我保证操作系统最终会将刷新的行写入磁盘,即使程序在两个流关闭之前崩溃(假设例如没有使用{}块,打电话给Flush())?

在我的场景中,我需要保持流打开(用于记录),所以我不能使用{}块,但我想确保即使程序崩溃,数据也将始终写入磁盘.如果电源关闭并且操作系统没有刷新到磁盘上,我可以负担得起丢失数据,但是否则我需要操作系统最终刷新,即使我从未正确调用流上的Close().

解决方法

是的,在StreamWriter上调用Flush将导致底层流被刷新. 4.5版本调用私有Flush(bool,bool)函数,该函数以:
if (flushStream)
{
    this.stream.Flush();
}

其中flushStream是第一个参数,this.stream是构造StreamWriter的流,而Flush()中的调用是Flush(true,true).

(答案的旧部分 – 我在回答时非常迂回.将答案的最相关部分移到顶部)

它没有在我可以找到的任何地方的文档中明确说明,但是通过传递另一个流构造的任何流类应该被假定为“取得该流的所有权”(除非另有特别调用).

也就是说,一旦使用fs构造了StreamWriter,就不应该自己对fs执行任何直接操作.

您从MSDN引用的部分与后面的句子有关:

This allows the encoder to keep its state (partial characters) so that it can encode the next block of characters correctly. This scenario affects UTF8 and UTF7 where certain characters can only be encoded after the encoder receives the adjacent character or characters.

也就是说,您可能已经将数据传递给Write,这样您就可以给它一些Unicode代理,但不是完整的字符. Flush不会将这些代理写入流中.只要你总是将格式良好的(完整的)字符串传递给Write,你就不需要关心这一点了.

Entitymanager.flush()与EntityManager.getTransaction()。commit-我应该首选什么?

Entitymanager.flush()与EntityManager.getTransaction()。commit-我应该首选什么?

更新数据库时我更喜欢什么?哪种方法的优缺点是什么,什么时候应该使用另一种方法?

public void disemployEmployee(Integer employeeId, Date endDate) {    Employee employee = (Employee)em.find("Employee", employeeId);    employee.getPeriod().setEndDate(endDate);    em.flush();}public void disemployEmployee(Integer employeeId, Date endDate) {    Employee employee = (Employee)em.find("Employee", employeeId);    em.getTransaction().begin();    employee.getPeriod().setEndDate(endDate);    em.getTransaction().commit();}

答案1

小编典典

在第一个示例中,对数据的更改在遇到刷新后会反映在数据库中,但仍在事务中。

但是在第二个示例中,您将立即提交事务。因此,对数据库所做的更改以及事务也在那里结束。

有时,刷新可能有助于将数据保留在正在进行的事务之间,然后最终提交更改。因此,如果以后发生某些问题,例如批量插入/更新,您也可以回滚以前的更改。

FileOutputStream:“ close”方法是否也调用“ flush”?

FileOutputStream:“ close”方法是否也调用“ flush”?

我对flush和close方法感到非常困惑。在我的代码中,我总是关闭我的FileOutputStream对象。但是我想知道,如果我必须在这里使用冲洗方法,在哪里可以使用它?

我将编写一个反复下载4或5个文件的项目。我将编写一个方法(用于下载文件),我的方法将处于循环中并重复下载文件。我的方法将具有这样的代码。

close方法调用flush还是在关闭之前必须使用冲洗?

try {    InputStream inputStream = con.getInputStream();    FileOutputStream outputStream = new FileOutputStream("C:\\programs\\TRYFILE.csv");    int bytesRead = -1;    byte[] buffer = new byte[4096];    while ((bytesRead = inputStream.read(buffer)) != -1) {    outputStream.write(buffer, 0, bytesRead);}} catch(Exception e) {    //} finally {    outputStream.close();    inputStream.close();}

请注意,该代码运行良好:成功下载了文件。但是我不确定要使用flush

答案1

小编典典

该方法flush用于“刷新”缓冲区中保留的字节。FileOutputStream不使用任何缓冲区,因此flush方法为空。是否调用它不会更改代码的结果。

使用缓冲的编写器时,方法close将显式调用flush

因此,当您要 在关闭流 之前和缓冲区已满之前(当缓冲区已满时,编写器无需等待刷新调用就开始写入数据)要写入数据时,需要调用flush 。

class的源代码FileOutputStream没有method的自定义版本flush。因此,flush使用的方法是其超类的版本OutputStream。刷新的代码OutputStream如下

public void flush() throws IOException {}

如您所见,这是一个不执行任何操作的空方法,因此调用它与否是相同的。

今天关于PHP FLUSH 函数 在IE11中 清除缓存的方法php清除缓存代码的介绍到此结束,谢谢您的阅读,有关angularjs – $httpBackend.flush()仍然需要超时来定义对象、c# – StreamWriter.Flush()还会调用FileStream.Flush()吗?、Entitymanager.flush()与EntityManager.getTransaction()。commit-我应该首选什么?、FileOutputStream:“ close”方法是否也调用“ flush”?等更多相关知识的信息可以在本站进行查询。

本文标签: