17.07.2015 Views

The Art of SQL Server FILESTREAM - Red Gate Software

The Art of SQL Server FILESTREAM - Red Gate Software

The Art of SQL Server FILESTREAM - Red Gate Software

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 12: Planning, Configuration and Best Practicesincoming request, the web server tells the client whether the server has a newer version<strong>of</strong> the file or not. <strong>The</strong> file needs to be downloaded only if the server has a newer versionor if the cache is expired.In the case <strong>of</strong> a <strong>FILESTREAM</strong> application, the data is stored and managed within thedatabase. <strong>The</strong> web server does not know about the modified status <strong>of</strong> the file. As a result,in most cases, the file is downloaded every time a request comes in. This adds considerableoverhead to the application, the database, and the web server.Having a time stamp or date column on the table that keeps track <strong>of</strong> modificationsdone on the <strong>FILESTREAM</strong> value will help you to implement cache control in your<strong>FILESTREAM</strong> web handler. When a request comes in from a client, you can examine thecache control headers to see whether the file on the server is newer than the file on theclient. If the file has not been modified since the client downloaded it, your handler cansend back an HTTP 304 response which tells the client to use its local copy <strong>of</strong> the file.Use a computed column to retrieve the file sizeWhile working with <strong>FILESTREAM</strong> databases, you might need to know the size <strong>of</strong> theBLOB value stored in the <strong>FILESTREAM</strong> column. To avoid calculating the length <strong>of</strong> eachBLOB value every time you need to query, you might decide to create a column andupdate it at the time <strong>of</strong> writing the <strong>FILESTREAM</strong> value.An easier option is to create a PERSISTED computed column that stores the length <strong>of</strong> thefile. Listing 12-6 shows how to add a computed column that stores the size <strong>of</strong> the BLOBvalue stored in a <strong>FILESTREAM</strong> column.ALTER TABLE ItemsADD FileSize AS DATALENGTH(ItemImage) PERSISTED;Listing 12-6:Adding a computed column to store the size <strong>of</strong> the BLOB value in a <strong>FILESTREAM</strong> column.455

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!